C program not working with errors related to C++ -
i wrote program school, keep getting c++ related errors (apparently)
#include <stdio.h> #define int num_of_chars 51 void switch (char *c) { //little letters if (((*c)>=97) && ((*c)<=122)) (*c)-=32; //capital letters if ((c>=65) && (c<=90)) (*c)+=32; //*c>=5 if ((c>=53) && (c<=57)) (*c)=56; //*c<5 if ((c>=48) && (c<=52)) (*c)=48; }*/ int main() { char string[51]; printf("please enter string \n"); scanf("%s", string); printf("%s => ", string); int i=0; char s[51]; while((string[i]!= "\0") && (i < num_of_chars)) { s[i]=switch (string[i]); i++; } printf("%s", s); return 0;*/ }
i'm getting errors /stray xxx in program , macro names must identified.
i'm kind of new c i'd appreciate if point me out errors in code are. thanks!!
there many issues. want program below. code compiles , works still absolutly horrible, respects intention.
try make better.
btw characters contained in string
variable changed, intended ?
#include <stdio.h> #define num_of_chars 51 // removed "int" char switchcase (char *c) // << need return char not void { // << name changed switchcase // c changed (*c), btw: *c without () ok //little letters if (((*c) >= 97) && ((*c) <= 122)) (*c) -= 32; //capital letters else if (((*c) >= 65) && ((*c) <= 90)) (*c) += 32; //*c>=5 else if (((*c) >= 53) && ((*c) <= 57)) (*c) = 56; //*c<5 else if (((*c) >= 48) && ((*c) <= 52)) (*c) = 48; return *c; } int main() { char string[51]; printf("please enter string \n"); scanf("%s", string); printf("%s => ", string); int = 0; char s[51]; while ((string[i] != '\0') && (i < num_of_chars)) { s[i] = switchcase(&string[i]); i++; //^ & missing here } s[i] = '\0'; // << forgot 0 terminator printf("%s", s); return 0; // << removed stray "*/" }
Comments
Post a Comment