copy and paste the below source code for analysis
i tried to change cin.get(c) and !cin.eof to c = getchar() and ((c=getchar()) != EOF) but it didn't work, tell me why??? it can be compiled but the characters i typed in was skipped oddly
if abcd is entered
bd will be displayed
i need to compile this source under the linux platform, so i need help to write a version of this program under c language instead of c++.........please help!!!
#include <iostream.h> // include file c++
#include <stdio.h> // c lang
#include <stdlib.h> // c lang
int main()
{
char c; // declaration of variable used to scan the stream of characters
while (!(cin.eof())) // reads input until end of file is reached
{
cin.get(c);
if (c != '/' && c != '"') // check for possible start of comment or quotation
printf("%c", c);
else if (c == '"') { // Finds start of quotation
printf("%c", c);
cin.get(c);
while (c != '"') {// Ignores characters inside quotation
printf("%c", c);
cin.get(c);
if (c == '\\') {// Check for '\"' characters inside string and ignores them
printf("%c", c);
cin.get(c);
if (c == '"')
printf("%c", c);
else
printf("%c", c);
cin.get(c);
}
if (cin.eof()) {// Displays error if program gets to the end of file before finding the closing quote
cerr <<"\n ------- ERROR!!! End of file reached before end of string!!! -------\n\n\n";
return EXIT_FAILURE;
}
}
if (c == '"') // Finds end of quotation
printf("%c", c);
}
else if(c == '/') {// Checks for // kind of comment
cin.get(c);
if (c == '/') {
while (c != '\n') {// Delete all characters until end of line is reached
cin.get(c);
if (c == '\n')
printf("%c", c);
else
printf("");
}
}
else if(c == '*') { // Checks for /* kind of comment
cin.get(c);
while (c != '*') { // Deletes all characters until '*' is found
printf("");
cin.get(c);
if (cin.eof()) { // Displays error if program gets to the end of file before finding the end of the comment
cerr <<"\n ------- ERROR!!! End of file reached before end of comment!!! ------- \n\n\n";
return EXIT_FAILURE;
}
}
if (c == '*') { // Finds possible end of comment
cin.get(c);
while (c != '/') {
printf("");
cin.get(c);
}
if (c == '/') // Confirms end of comment
printf("");
}
}
}
else
printf("%c", c);
}
return EXIT_SUCCESS;
}