Hi,
I have an assignment for homework which is giving me trouble. You can see by the code I have started I am just stuck. Also this code (bad as it is) is 100% mine no copying pasting etc... The assisnment is such that we have to write a program to remove comments and replace them with a space. A comment in our case is considered to start with /* and end with */ so if you had /*abc*/ abc would be replaced with a space. It needs to operate with standard Input Output streams. So the programs name is decomment and the execution would look something like this
decomment < somefile.c > somefilewithoutcomments.c 2> errorandwarningmessages
I'm a bit lost but more then willing to put the work in to get it right. Any help is greatly appreciated. My code isn't to great it needs work, I'm not even sure what to return I know it needs to return success and non-success(errors) but not sure how to do that. But as I said I will work to make it better.
Code:#include<stdio.h> int main () enum state {Out, Slash, In, Star;} int c = getchar(); Switch (state) {case Out: if c=='/' state = Slash break; case Slash: if c =='*' state = In else if(c!='*') state = Out break; case In: if c=='*' state = star break; case Star: if c == '/' state = Out else if (c!='*') state = In }