Hi, I'd like to first of all thank people for the help, my little string converter program is nearly finished, I am only stuck on the function of converting the letters from the string from lower case to upper case and vice versa, this is what the code looks like now:
Code:
#include <stdio.h>
#include <ctype.h>
#define STRINGSIZE 100
void getString(char *string);
void reverseCase(char *string);
int numGraph(char *string);
int main()
{
char string[STRINGSIZE];
int count;
getString(string);
printf("Entered string => %s\n",string);
count = numGraph(string);
printf("Number of graphic characters in string = %d\n", count);
reverseCase(string);
printf("Reverse case => %s\n",string);
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.
*/
while((*string = getchar()) != EOF)
putchar(isupper(string) ? tolower(string) : toupper(string));
}
int numGraph(char *string)
{
/* Calculate the number of printable graphic characters in the
string.
*/
int i,count;
for(i = 0,count = 0;string[i] != '\0';i++)
{
if (isgraph((int)string[i])) count++;
}
return count;
}
void getString(char *string)
{
printf("Please enter a string to process\n");
fgets(string, STRINGSIZE, stdin);
}
It compiles and runs fine until it gets to the reverseCase function that thrwos me a segmentation fault. Anyone know what I am doing wrong?
Thanks