By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,246 Members | 1,480 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,246 IT Pros & Developers. It's quick & easy.

why doesn't my while loop finish?

P: n/a

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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a


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 discussion thread is closed

Replies have been disabled for this discussion.