Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

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.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-02-2008, 02:41 PM
simpatico simpatico is offline
Newbie
 
Join Date: May 2007
Posts: 8
Rep Power: 0
simpatico is on a distinguished road
Default wats the wrong with this code

hi wats the wrong with code
tell me
when i excute it ,a message appear and say aranoooo
Code:
#include <stdio.h>

/*
The input file (weight.txt) look something like this
4
0 0 0 21
0 0 8 17
0 8 0 16
21 17 16 0

The first line contains n, the number of nodes.
Next is an nxn matrix containg the distances between the nodes
NOTE: The distance between a node and itself should be 0
*/

int n; /* The number of nodes in the graph */

int weight[100][100]; /* weight[i][j] is the distance between node i and node j;
if there is no path between i and j, weight[i][j] should
be 0 */

char inTree[100]; /* inTree[i] is 1 if the node i is already in the minimum
spanning tree; 0 otherwise*/

int d[100]; /* d[i] is the distance between node i and the minimum spanning
tree; this is initially infinity (100000); if i is already in
the tree, then d[i] is undefined;
this is just a temporary variable. It's not necessary but speeds
up execution considerably (by a factor of n) */

int whoTo[100]; /* whoTo[i] holds the index of the node i would have to be
linked to in order to get a distance of d[i] */

/* updateDistances(int target)
should be called immediately after target is added to the tree;
updates d so that the values are correct (goes through target's
neighbours making sure that the distances between them and the tree
are indeed minimum)
*/
void updateDistances(int target) {
int i;
for (i = 0; i < n; ++i)
if ((weight[target][i] != 0) && (d[i] > weight[target][i])) {
d[i] = weight[target][i];
whoTo[i] = target;
}
}

int main(int argc, char *argv[]) {
FILE *f = fopen("dist.txt", "r");
fscanf(f, "%d", &n);
int i, j;
for (i = 0; i < n; ++i)
for (j = 0; j < n; ++j)
fscanf(f, "%d", &weight[i][j]);
fclose(f);

/* Initialise d with infinity */
for (i = 0; i < n; ++i)
d[i] = 100000;

/* Mark all nodes as NOT beeing in the minimum spanning tree */
for (i = 0; i < n; ++i)
inTree[i] = 0;

/* Add the first node to the tree */
printf("Adding node %c\n", 0 + 'A');
inTree[0] = 1;
updateDistances(0);

int total = 0;
int treeSize;
for (treeSize = 1; treeSize < n; ++treeSize) {
/* Find the node with the smallest distance to the tree */
int min = -1;
for (i = 0; i < n; ++i)
if (!inTree[i])
if ((min == -1) || (d[min] > d[i]))
min = i;

/* And add it */
printf("Adding edge %c-%c\n", whoTo[min] + 'A', min + 'A');
inTree[min] = 1;
total += d[min];

updateDistances(min);
}

printf("Total distance: %d\n", total);

return 0;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-03-2008, 03:05 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,057
Last Blog:
wxWidgets is NOT code ...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

What is the error message?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-03-2008, 10:36 PM
simpatico simpatico is offline
Newbie
 
Join Date: May 2007
Posts: 8
Rep Power: 0
simpatico is on a distinguished road
Default

hi this is the message which apeer
Attached Thumbnails
To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-03-2008, 11:48 PM
v0id's Avatar   
v0id v0id is offline
<img src="http://forum.codecall.net/images/userbar/supermod.png" alt="Super Moderator">
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,468
Last Blog:
CherryPy(thon)
Rep Power: 27
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

It seems like you're showing us the wrong error-message. According to the error-message you're using the function, assert, and a pointer called, stream, but when I look at the code you've provided, I see neither of them.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-05-2008, 10:58 AM
simpatico simpatico is offline
Newbie
 
Join Date: May 2007
Posts: 8
Rep Power: 0
simpatico is on a distinguished road
Default

yes but im already cant understand wats this mean
Code:
int main(int argc, char *argv[]) {
	FILE *f = fopen("dist.txt", "r");
	fscanf(f, "%d", &n);
	int i, j;
	for (i = 0; i < n; ++i)
		for (j = 0; j < n; ++j)
			fscanf(f, "%d", &weight[i][j]);
	fclose(f);

plzzzzzzzzzzzzzzz help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 03-05-2008, 10:27 PM
dargueta dargueta is offline
Guru
 
Join Date: Oct 2007
Age: 18
Posts: 509
Last Blog:
Programs Under the Hoo...
Rep Power: 10
dargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the rough
Default

v0id: ASSERT() is automatically included in debug versions of standard libraries, but is bypassed in release versions. The error is in something he passes to fscanf.

simpatico: Check to make sure that the pointer to the file, f, isn't null. What most likely happened is that fopen failed to open the file, and then you're passing a null pointer into fscanf, which is causing the error. Make sure the file path is correct in your call to fopen.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-06-2008, 12:59 AM
simpatico simpatico is offline
Newbie
 
Join Date: May 2007
Posts: 8
Rep Power: 0
simpatico is on a distinguished road
Default

thanks every body
i solved the problem
thank u veery much for helping me
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-06-2008, 07:41 AM
v0id's Avatar   
v0id v0id is offline
<img src="http://forum.codecall.net/images/userbar/supermod.png" alt="Super Moderator">
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,468
Last Blog:
CherryPy(thon)
Rep Power: 27
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

Quote:
Originally Posted by dargueta
ASSERT() is automatically included in debug versions of standard libraries
Oh, I wasn't aware that Visual C++ has chosen to do that. I've never worked with Visual C++. Thank you for the information.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 03-06-2008, 08:15 AM
Jordan's Avatar   
Jordan Jordan is online now
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 26
Posts: 5,998
Last Blog:
SAP, ERP and EDI
Rep Power: 20
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

Quote:
Originally Posted by dargueta View Post
v0id: ASSERT() is automatically included in debug versions of standard libraries, but is bypassed in release versions. The error is in something he passes to fscanf.

simpatico: Check to make sure that the pointer to the file, f, isn't null. What most likely happened is that fopen failed to open the file, and then you're passing a null pointer into fscanf, which is causing the error. Make sure the file path is correct in your call to fopen.
Excellent information dargueta. +Rep given.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
Don't hesitate to ask any questions that you have! Check out our ASCII Calculator!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 03-06-2008, 06:10 PM
dargueta dargueta is offline
Guru
 
Join Date: Oct 2007
Age: 18
Posts: 509
Last Blog:
Programs Under the Hoo...
Rep Power: 10
dargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the roughdargueta is a jewel in the rough
Default

Thanks. And it's not just C++; it just depends on the compiler you have.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic Calculator AfTriX VB Tutorials 3 02-29-2008 08:53 AM
Generating executable machine code steffanp General Programming 5 02-03-2008 10:01 AM
Please Help With A C Program!! siren C and C++ 7 04-17-2007 08:45 AM
What is wrong with this code convertion ? Jophry C and C++ 1 01-04-2007 12:10 PM


All times are GMT -5. The time now is 06:13 PM.

Contest Stats

Xav ........ 162.68
neerlin ........ 100
satrian ........ 100
delia ........ 100
chili5 ........ 70.08
morefood2001 ........ 42.41
MeTh0Dz|Reb0rn ........ 28.44
RyanTuosto ........ 20
gamiR ........ 19.64
John ........ 14.46

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 68%

Ads