Need help with this problem:
Convert all the letters in file to lower case, and any non letter character is converted to a space. Consecutive spaces should be compressed into one single space.
This is what I have so far:
Code:
#include <stdio.h>
#define FALSE 0
#define TRUE 1
int replace(int c){
if (ispunct(c) || isdigit(c))
{
putchar(' ');
while ((c = getchar() ) != EOF && ispunct(c) || isdigit(c))
{ }
}
if (c != EOF)
return c;
}
int main()
{
int c;
int start= TRUE;
while ( (c = getchar() ) != EOF)
{
if (isspace(c))
{
if(start==FALSE)
putchar(' ');
while ( (c = getchar() ) != EOF && isspace(c))
{}
}
if (c != EOF)
{
putchar(tolower(replace((c))));
start = FALSE;
}
} printf("\n");
}
The test file consists of:
Code:
Hello1431387409876187461203470981743Hello (works)
Hello@$#%@%#$%@#$%^&(*%&^(*$%*Hello (works)
Hello!2@3$4%4^7&6&5$6&5%4%3$2$5$3Hello (works)
Hello11$%33%%3452345$%$%#45453$%Hello (works)
Hello Hello (works)
Hello $1%4# Hello (doesn't work)
desired output:
Code:
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
current output:
Code:
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
hope this is clear, any suggestions?