Hi, I need urgent help for this program, sorry I am new to C and I got this code:
What I am trying to achieve is for the program to first ask me to input a string, then I need the program to show me the string I entered, count the number of characters entered and then convert the string to upper case or vice versa depending on the string I entered.Code:#include <stdio.h> #define STRINGSIZE 100 void getString(char *string); void reverseCase(char *string); int numGraph(char *string); int main() { char string[STRINGSIZE]; int count; char c; getString(string); printf("Entered string => %s", c); count = numGraph(string); printf("Number of graphic characters in string = %d\n", count); reverseCase(string); printf("Reverse case => %s", c); return 0; } void reverseCase(char *string) { /* Reverse the case of all alphabetic characters in the string. That is, all upper case characters become lower case and all lower case become upper case. */ char c; while((c = getchar()) != EOF) putchar(isupper(c) ? tolower(c) : toupper(c)); } int numGraph(char *string) { /* Calculate the number of printable graphic characters in the string. */ int count; while (string != '\0') { if (isgraph((int) *string)) count++; } return count; } void getString(char *string) { char c; printf("Please enter a string to process\n"); scanf("%s", c); fgets(string, STRINGSIZE, stdin); }
This code is for some reason throwing me a runtime error, I am not sure what I am doing wrong. Any help will be appreciated. Thanks.



LinkBack URL
About LinkBacks


