ungeilimage's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 7 (0.06 per day)
- Joined:
- 27-January 13
- Profile Views:
- 329
- Last Active:
Mar 07 2013 02:38 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: filter program to remove comments
Posted 7 Mar 2013
JackOfAllTrades, on 07 March 2013 - 02:27 PM, said:I would suspect that if the assignment was to "create a filter", SOMETHING about creating a filter would have been covered in the class or the textbook.
EDIT: Like snoopy11 intimates, could it be something like this?
% a.out < inputfile > outputfile
?
Yea, I guess you are right. The professor wants me to do something line a < a.txt and then prints to stdout.#include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]) { char c; while ((c=getchar() != EOF)) { if (c == '/') { c = getchar(); if (c == '/') { while (1) { c = getchar(); if (c == '\n') goto label; } } if (c == '*') { while (1) { c = getchar(); if (c == '*') { c = getchar(); if (c == '/') { while (1) { c = getchar(); goto label; } } } } } } label: putchar(c); } return EXIT_SUCCESS; }
Here is my code. I changed it from opening file from fopen. But now the output is just a mass, seems something wrong with memory. -
In Topic: gcc warn uninitialized string
Posted 4 Mar 2013
sepp2k, on 04 March 2013 - 10:03 PM, said:
ungeilimage, on 05 March 2013 - 05:56 AM, said:OK, I added a malloc to the pointer and it worked.
Since MAX_INPUT looks to be a #defined constant, you can just use a static array rather than malloc: char input[MAX_INPUT];. If you do use malloc, make sure to call free on it afterwards.
Quote
However, strcmp does not work now, whatever I enter, it always returns a non-zero number.
From man fgets:
Quote
If a newline is read, it is stored into the buffer.
So if the user enters "y", input will contain the string "y\n", not just "y".
YES!! Added y\n and it worked!! Thanks a lot! -
In Topic: gcc warn uninitialized string
Posted 4 Mar 2013
OK, I added a malloc to the pointer and it worked. However, strcmp does not work now, whatever I enter, it always returns a non-zero number. -
In Topic: gcc warn uninitialized string
Posted 4 Mar 2013
The last line is meaningless, can ignore it. (printf("%s", input))
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
ungeilimage hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
ungeilimage has no profile comments yet. Why not say hello?