Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This code came from Zyooks I was to add a printf statement to get this answer: xyz xzy yxz yzx zxy zyx I'm a newbie trying to understand char and integer literals.

#include <stdio.h>
int main(void) {
   char a;
   char b;
   char c;
   scanf(" %c ", &a);
   scanf(" %c ", &b);
   scanf(" %c ", &c);

//this is the line I added to get this output    xyz  xzy   yxz  yzx   zxy  zyx  
  printf("%c %c %c %c %c %c," abc, acb, bac, bca, cab, cba);  
						       
printf("\n");
return 0;
}


What I have tried:

This is C code. I have tried several changes, but none work.
Posted
Updated 18-Sep-19 14:03pm

you can't concat variables like that

the compiler sees abc as an undefined variable.

what you need is like.
C++
printf("%c%c%c ",a,b,c);
printf("%c%c%c ",b,c,a);
printf("%c%c%c ",c,a,b);

etc
 
Share this answer
 
v3
Comments
Member 14597159 19-Sep-19 14:37pm    
Thanks. You solved this 84 year old Newbie's problem.
Quote:
What is wrong with the printf statement in this code

Many things, S1 code is how you should do.
C++
printf("%c %c %c %c %c %c," abc, acb, bac, bca, cab, cba);
//      ^ this is for 1 char only, but you want 3 chars at a time
//                       ^ the comma, here, should be after double quptes
//                          ^ here is a new undefined variable, not a combination of 3 variables
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900