473,385 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

why doesn't my while loop finish?


I didn't finish my program yet but in the input function there is a
problem.When i enter E character while loop doesn't end. Why? Can
anybody help me where is the error? From now, thanks ;)

#include <stdio.h>
#include <stdlib.h>

struct MinSpanTree{
char vertex[20];
char edge[20];
int weight[80];
struct node *left,*right;

}graph,first,last,ed;
void input();
void makeGraph();

//char vrtx[20];

int count;
int main(){
input();
makeGraph();

return 0;
}
void input(){

printf("Enter the starting vertex of the edge!(To exit enter E)\n");
scanf("%s",first.vertex);
count=0;

while(first.vertex!="E"){

printf("Enter the ending vertex of the edge!\n");
scanf("%s",last.vertex);
printf("Enter the weight of the edge!\n");
scanf("%d",ed.weight);
count++;
printf("Enter the starting vertex of the edge!(To exit enter E)\n");
scanf("%s",first.vertex);

}
}

void makeGraph(){
}

Jan 23 '07 #1
6 2689
ok i found my mistake it will be like that :

while(!(first.vertex[0]=='E')){

printf("Enter the ending vertex of the edge!\n");
scanf("%s",last.vertex);
printf("Enter the weight of the edge!\n");
scanf("%d",ed.weight);
count++;
printf("Enter the starting vertex of the edge!(To exit enter E)\n");
scanf("%s",first.vertex);

}

Jan 23 '07 #2

Thats correct !

iskeletor wrote:
ok i found my mistake it will be like that :

while(!(first.vertex[0]=='E')){

printf("Enter the ending vertex of the edge!\n");
scanf("%s",last.vertex);
printf("Enter the weight of the edge!\n");
scanf("%d",ed.weight);
count++;
printf("Enter the starting vertex of the edge!(To exit enter E)\n");
scanf("%s",first.vertex);

}
Jan 23 '07 #3
iskeletor wrote:
I didn't finish my program yet but in the input function there is a
problem.When i enter E character while loop doesn't end. Why? Can
anybody help me where is the error? From now, thanks ;)
while(first.vertex!="E"){
This is comparing the pointer first.vertex with the pointer to the
constant char array "E". You need to look up and use strcmp.
Jan 23 '07 #4
"John Turner" <xe*******@yahoo.comwrote in message
news:ep**********@internet.csl.co.uk...
iskeletor wrote:
>I didn't finish my program yet but in the input function there is a
problem.When i enter E character while loop doesn't end. Why? Can
anybody help me where is the error? From now, thanks ;)
> while(first.vertex!="E"){
This is comparing the pointer first.vertex with the pointer to the
constant char array "E". You need to look up and use strcmp.
As I'm reading it, this loop should also never terminate (permanently true
while condition).

--
David T. Ashley (dt*@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
Jan 23 '07 #5
iskeletor wrote:
I didn't finish my program yet but in the input function there is a
problem.When i enter E character while loop doesn't end. Why?

#include <stdio.h>
#include <stdlib.h>

struct MinSpanTree{
char vertex[20];
char edge[20];
int weight[80];
struct node *left,*right;

}graph,first,last,ed;
void input();
void makeGraph();

//char vrtx[20];

int count;
int main(){
input();
makeGraph();

return 0;
}
void input(){

printf("Enter the starting vertex of the edge!(To exit enter E)\n");
scanf("%s",first.vertex);
count=0;

while(first.vertex!="E"){

printf("Enter the ending vertex of the edge!\n");
scanf("%s",last.vertex);
printf("Enter the weight of the edge!\n");
scanf("%d",ed.weight);
count++;
printf("Enter the starting vertex of the edge!(To exit enter E)\n");
scanf("%s",first.vertex);

}
}
de*******@gmail.com later wrote:
Thats correct !

iskeletor wrote:
>>ok i found my mistake it will be like that :

while(!(first.vertex[0]=='E')){
That change will terminate if the first character of input is E. Since
you declared vertex to hold up to 19 characters, presumably you want to
accept names like Charley, Tricia, and Elaine. Elaine will always be
excluded. You should use strcmp to compare the complete string,
possibly after converting to uniform case.

--
Thad
Jan 24 '07 #6


i got it,it is all wrong, because i am writing over the data which i
hold before in the array.SO the existing data is being deleted.I
changed the codes.Thanx for helps ;)

Jan 24 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tim::.. | last post by:
Hi can someone please give me some help with this little problem I am having with the following loop ...:: CODE ::. < 'Load XM set xml = Server.CreateObject("Microsoft.XMLDOM" xml.async = fals...
34
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and...
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
3
by: Robert A. van Ginkel | last post by:
In news:OZ0W9RsdDHA.2432@TK2MSFTNGP10.phx.gbl... I ask the question how I can see if all the data is on the other side of the connection. I got as answer that I should use the blocking property. I...
7
by: Andrea Moro | last post by:
I do a stupid thing ... new webform, in the page_load event added this code dim i as int64 do while true i = i + 1 loop run the project, stop adfter a while ... and then putted a...
4
by: outforblood74 | last post by:
Ok here's the deal, the for each statment using VB 6 doesn't loop all the objects. I would like it to close all the IE browsers that are open, but it doesn't work. And now I'm concerned that its...
12
by: Howard | last post by:
Hello everyone (total VB.NET beginner here), I'm reading the "SAMS Teach Yourself VB.NET In 21 Days" book, and came across an exercise that I can't get to work. The exercise asks that you create...
0
by: SMasterson | last post by:
Hi all, I am trying to execute code to insert records from an Access 2002 Xtab query to a remote Sql_Server table. I keep getting a random problem where the Access query doesn't complete before the...
13
by: icarus | last post by:
Hi all, i'm new to python. Learning on my own how to ask a user to finish a loop or not. For some reason, it behaves as infinite loop although I changed its condition. Please tell me what I'm...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.