tag:blogger.com,1999:blog-2807403883562053852.post2894686644191314644..comments2024-03-27T08:40:31.785-06:00Comments on Clayton Cramer.: Not a Good DayClayton Cramerhttp://www.blogger.com/profile/03258083387204776812noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-2807403883562053852.post-17531364730662582772019-06-10T00:16:38.722-06:002019-06-10T00:16:38.722-06:00Thanks for all the help. I am slowly working my w...Thanks for all the help. I am slowly working my way through the real code. char *list[] means to malloc the memory before copying a string into it. The things you forget.Clayton Cramerhttps://www.blogger.com/profile/03258083387204776812noreply@blogger.comtag:blogger.com,1999:blog-2807403883562053852.post-5067290670702769582019-06-09T10:44:01.212-06:002019-06-09T10:44:01.212-06:00I would check inputFile != null to confirm the fil...I would check inputFile != null to confirm the file open worked, and not assign inputString = fgets(...); rather just test the return value != null to confirm the fgets successfully copied;<br /><br /> if (argc < 2) {<br /> /* print usage string */<br /> exit(-1);<br /> }<br /> <br /> inputFile = fopen (argv[1] , "r");<br /> if (inputFile == NULL) perror ("Error opening file");<br /> else {<br /> if ( fgets (inputString, 500 , inputFile) != NULL )<br /> printf("%s\n", inputString);<br /> else<br /> printf("Could not read from file\n");<br /><br /> fclose (pFile);<br /> }<br /> <br />The only thing I see that could cause a seg fault on the fgets line is if the file open failed for some reason.MattJhttps://www.blogger.com/profile/07521394649468155883noreply@blogger.comtag:blogger.com,1999:blog-2807403883562053852.post-33032495438736927032019-06-09T09:59:21.507-06:002019-06-09T09:59:21.507-06:00A quick search suggests that the file isn't in...A quick search suggests that the file isn't in the current directory and fopen is returning NULL.Rick Chttps://www.blogger.com/profile/10992428161064901136noreply@blogger.comtag:blogger.com,1999:blog-2807403883562053852.post-68367055263496931432019-06-09T09:14:18.593-06:002019-06-09T09:14:18.593-06:00You are re-assigning inputString with the result o...You are re-assigning inputString with the result of fgets (which is an int).<br /><br />Also, when running from the debugger, did you remember to do a set args filename.txt? The fopen will fail if argv[1] isn't set.<br />coderpunkhttps://www.blogger.com/profile/15780416627307204084noreply@blogger.com