| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| P D Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				| How do I Printf a Semicolon between 2 bits of text ? |  
				|  Posted: Fri Jan 30, 2004 5:08 am |   |  
				| 
 |  
				| Hi everyone, 
 How do I printf a Semicolon between 2 bits of text? i.e.
 
 printf( "Here is the "problem" I have" );
 
 I want to see :
 
 Here is the "problem" I have
 
 appear on my screen.
 
 Thanks in advance,
   
 Peter
 |  | 
	
		|  | 
	
		| P D Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				| Sorry, Not Semicolon - I mean Inverted commas |  
				|  Posted: Fri Jan 30, 2004 5:12 am |   |  
				| 
 |  
				| Sorry, Not Semicolon - I mean Inverted commas 
 Peter
 |  | 
	
		|  | 
	
		| wedilo 
 
 
 Joined: 16 Sep 2003
 Posts: 71
 Location: Moers, Germany
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Jan 30, 2004 5:28 am |   |  
				| 
 |  
				| Hello P D, Normally you can use the fprintf command with %c and append the char as ascii No. 34
 
 But I think the following way with the Backslash is also possible.
 
 34dez = 22hex
 
 
  	  | Code: |  	  | printf( "Here is the \x22problem\x22 I have" );    ???
 
 or...
 
 printf( "Here is the '\x22'problem'\x22' I have" );
 
 or...
 
 printf( "Here is the 'problem' I have" );    :-)
 
 
 | 
 
 I can't try it here.  Please try it out and inform me...
 
 Hope to help you
 73 Sven
 |  | 
	
		|  | 
	
		| Ttelmah Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Fri Jan 30, 2004 5:43 am |   |  
				| 
 |  
				|  	  | wedilo wrote: |  	  | Hello P D, Normally you can use the fprintf command with %c and append the char as ascii No. 34
 
 But I think the following way with the Backslash is also possible.
 
 34dez = 22hex
 
 
  	  | Code: |  	  | printf( "Here is the \x22problem\x22 I have" );    ???
 
 or...
 
 printf( "Here is the '\x22'problem'\x22' I have" );
 
 or...
 
 printf( "Here is the 'problem' I have" );    :-)
 
 
 | 
 
 I can't try it here.  Please try it out and inform me...
 
 Hope to help you
 73 Sven
 | 
 
 Potentially you can put any ASCII value into a string using the \nnn format.
 The allowable 'extra' string characters are:
 \a 'bell' alert character
 \b 'backspace'
 \f 'formfeed'
 \n 'newline'
 \r 'carriage return'
 \t 'horizontal tab'
 \v 'vertical tab'
 \\ the bakslash character itself.
 \? the ? character
 \' the single quote character
 \" the double quote character
 \ooo Any ASCII character. Three octal digits
 \xhh Any ASCII character. Two hex digits.
 
 I think:
 
  	  | Code: |  	  | printf( "Here is the \"problem\" I have" );
 
 | 
 
 Is probably clearer, and easier to remember.
 
 Best Wishes
 |  | 
	
		|  | 
	
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Fri Jan 30, 2004 9:53 am |   |  
				| 
 |  
				| Hi, 
 I finally got
 
 printf( "Here is the %Cproblem%C I have", 0x22, 0x22 );
 
 to work
 
 I think I tried the
 
 printf( "Here is the '\x22'problem'\x22' I have" );
 
 option but as soon as it saw the " it thought that was the end of the string and carried on to make nonsense of the rest.
 
 I can't use ' as the " is part of a fixed protocol I am working on.
 
 I will try all the others and see what works and which is the most compact.
 
 Thanks for the help everyone,
 
 Peter
 |  | 
	
		|  | 
	
		| Al 
 
 
 Joined: 13 Nov 2003
 Posts: 28
 Location: Belfast
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Jan 30, 2004 10:41 am |   |  
				| 
 |  
				| This works for me and it is simple. 
 printf("\r\n the \"problem\" i am having");
  _________________
 Alan Murray
 |  | 
	
		|  | 
	
		| dgoldman 
 
 
 Joined: 24 Aug 2010
 Posts: 7
 
 
 
			    
 
 | 
			
				| A broken corner case to watch for: |  
				|  Posted: Tue Aug 24, 2010 2:52 pm |   |  
				| 
 |  
				| Broken corner case to watch for: 
 #define FOO  "D=1\""
 printf(FOO);
 
 doesn't work on PCWH 4.111.    I think it is the double "".
 
 To get this to work, change to
 #define FOO  "D=1\x22"
 printf(FOO);
 |  | 
	
		|  | 
	
		| Wayne_ 
 
 
 Joined: 10 Oct 2007
 Posts: 681
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Aug 25, 2010 1:54 am |   |  
				| 
 |  
				| the \ is the escape char in C, if you escape a " e.g. "\"" then the compiler should ignore this as a start/end of string qualifier and just use it as a quote char. 
 printf ("Here is the \"problem\" I have");
 
 Should work, if it does not then there is an error in the compiler.
 
 To actually display a \ you would
 printf("\\");
 |  | 
	
		|  | 
	
		| Gabriel 
 
 
 Joined: 03 Aug 2009
 Posts: 1074
 Location: Panama
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Aug 25, 2010 7:40 am |   |  
				| 
 |  
				| This is what I used in my code: 
  	  | Code: |  	  | printf("AT+CPMS=\"ME\",\"ME\",\"ME\"");
 | 
 _________________
 CCS PCM 5.078 & CCS PCH 5.093
 |  | 
	
		|  | 
	
		|  |