![]() |
| | #1 |
| Rebooted Join Date: Apr 2002
Posts: 281
| Core Dump / Segmentation Fault Code: int main(int argc, char *argv[]) {
char *sFileName, // This is the name of the file to pass to gcc/g++
*sFileExt, // and its file extension
*sOutName, // This is the name of the output file for gcc/g++ (-o)
...
cout << "Makefile name: ";
cout << "DEBUG:: Breakpoint 1" << endl;
scanf("%s", &sOutName); // THIS IS [EDIT] NOT [\EDIT] WHERE THE SEGMENTATION FAULT IS
cout << "DEBUG:: Breakpoint 2" << endl;
sOutName = substr(sOutName, 0, (strchr(sOutName, '.')-sOutName)); // strip all extensions // THIS IS WHERE THE SEG. FAULT IS
__________________ Compilers: GCC on Red Hat 8.1 (Primary) GCC on Mac OS X 10.2.4 (Secondary) Others: MinGW on XP Last edited by Inquirer; 04-08-2003 at 05:36 PM. |
| Inquirer is offline | |
| | #2 | |
| Rebooted Join Date: Apr 2002
Posts: 281
| When i do that, i get these: Quote:
Code: 59: cout << "Makefile name: ";
60: cout << "DEBUG:: Breakpoint 1" << endl;
61: //scanf("%s", &sOutName);
62: fgets( sOutName, sizeof( sOutName ), stdin );
63: cout << "DEBUG:: Breakpoint 2" << endl;
64: sOutName = substr(sOutName, 0, (strchr(sOutName, '.')-sOutName)); // strip all extensions
__________________ Compilers: GCC on Red Hat 8.1 (Primary) GCC on Mac OS X 10.2.4 (Secondary) Others: MinGW on XP | |
| Inquirer is offline | |
| | #3 |
| Comment your source code! Join Date: Apr 2002
Posts: 533
| Dont use pointers to strings! If you're using C++ why not just write a string class or steal one from the college boards or something steal apstring I wrote one for my system CString (original isn't it?) Automatic resizing etc. Checks for outofbounds indexing and bad pointers (but I added HUGE amounts of debug code to actually check the whole program, not just where CString is used) |
| Lynux-Penguin is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What am I doing worng? Segmentation fault, core dump | cookie | C Programming | 4 | 06-08-2007 09:59 AM |
| Segmentation fault, core dumped | dweenigma | C Programming | 2 | 05-21-2007 03:50 PM |
| Locating A Segmentation Fault | Stack Overflow | C Programming | 12 | 12-14-2004 01:33 PM |
| Segmentation fault (core dumped) | JYSN | C Programming | 1 | 02-21-2002 03:24 AM |
| segmentation core dump - need help | knight101 | C++ Programming | 1 | 11-26-2001 04:43 PM |