c Shelling problem - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: General (http://qbasicnews.com/newforum/forum-6.html) +--- Forum: General/Misc (http://qbasicnews.com/newforum/forum-18.html) +---- Forum: General Programming (http://qbasicnews.com/newforum/forum-20.html) +---- Thread: c Shelling problem (/thread-9936.html) |
c Shelling problem - wallace - 03-02-2007 This doesn't work for some reason. It fails on fflush, and when I do get past that it doesn't register when I press enter. Code: int main(int argc, char *argv[]){ c Shelling problem - LooseCaboose - 03-02-2007 Couple of things: What does startargs() do? What are you expecting fflush() to do? How exactly does fflush() fail? getchar() buffers input, so it will not return until you press return. The returned value will be the last character entered before pressing return, therefore getchar() won't return '\n'. The first argument to strcat is the destination string, it should not be a literal. The statement: Code: printf("%s", strcat(strcat("/n", path), " ")); Code: printf("%s\n", path); Your other strcat: Code: strcat(tmp, &c); Code: int len = strlen(tmp); Nitpicks: You don't need to cast the return value of malloc() in C. Not doing the cast can actually help find errors in some cases. You shouldn't use // comments in C. You should place all variable declarations before any statements in C. This: Code: args[0] = "clear"; //this will fail the internal test and be sent to UNIX as an external command Code: char *p = NULL; Code: memset(tmp, 0, 256); //Flash reset of tmp, faster than for loop Code: tmp[0] = '\0'; This comment: Code: //Analyze looks at the args[] array so I copy the commandline arguments to it 1. If you didn't initalise it, it is probably not NULL 2. If you didn't malloc it, don't try and free it. Its not your responsibility. 3. If you did malloc it, make sure you free it, otherwise you have a memory leak. c Shelling problem - DrV - 03-02-2007 Not sure exactly what you're trying to do with fflush() either, but you can't use it to "flush" input - it only works on output streams. EDIT: also, ' Analyzer; ' is not a function call - you must use parentheses even if there are no arguments. |