|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
hi i need help for this code
every time i try to excute the program there be some mistake and i dont know wats the wrong can any one help me plz Quote:
Last edited by simpatico; 03-02-2008 at 03:33 PM. |
| Sponsored Links |
|
|
|
|||
|
Hi simpatico,
Your code seemed to work for me. Here is the output I received: Adding node A Adding edge A-D Adding edge D-C Adding edge C-B Total distance: 45 A couple of things to point on, however. At the beginning of your program (in the comments), you said that the text file's name was 'weight.txt'. However, in your code you are opening the file 'dist.txt' for reading. This threw me off a little bit, and if you haven't worked on your code in a while, this might throw you off as well. Also, if your program cannot find the file you are looking for and try to input information from that (like, say, by using fscanf), this could cause your program to crash. I know that when I tried to run the program with the text file named 'weight.txt' (ok, I didn't read the code close enough the first time round), I got an assert failure on line 52. If you have been getting an assert failure, it's because your program is not finding the file you are trying to open. You might want to try and check first to see if the file is open before reading from it. Something like the following should do: Code:
int main(int argc, char *argv[]) {
FILE *f = fopen("dist.txt", "r");
if(f == NULL){
printf("ERROR: Cannot find specified file.\n");
return -1;
}
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Basic Calculator | AfTriX | VB Tutorials | 3 | 02-29-2008 09:53 AM |
| Generating executable machine code | steffanp | General Programming | 5 | 02-03-2008 11:01 AM |
| RAW image code / data | mpcode | General Programming | 1 | 04-30-2007 12:01 PM |
| Where to Put PHP Code | clookid | PHP Tutorials | 1 | 01-11-2007 09:44 PM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |