I am new to C programming, i am currently working on a program where i must accept keyboard input and reproduce the text after eliminating white space. unless the text is in a string literal, then it must be reproduced with spaces. i have the first part (printing without spaces) but im not quite sure how to make it print normally within string literals....can anyone help me? here is my code
Code:#include <stdio.h> int main() { int c; printf("This program eliminates whitespace from an input stream,\n"); printf("except from within string literals in double quotes.\n"); printf("\n"); printf("Type characters, and enter EOF after <enter> to finish:\n"); while ((c = getchar()) != EOF) if ( c != ' ') putchar(c); system("pause"); return 0; }



LinkBack URL
About LinkBacks




but if you want to nitpick then the flag solution won't work either because if it sees a quote it won't know if the quote is terminated or not. the output will be wrong unless you write a case to find the string literals first and figure out how to handle an odd number of them.