i just need that for loop to work in the method i dunno what i need to add to it to get it working
i just need that for loop to work in the method i dunno what i need to add to it to get it working
atm i aint really worried bout the buffer ect atm im trying to get this function working
ok ill start it off simple
this is my function
Code:void places() { char pos[2][16]; char place[11][11]; int point[2]; int i, x, wrong, flag; for(i=0;i<2;i++) // loops round twice allowing the input of 2 points { if(wrong!=1) { if(i==0){printf("\n Please enter your Start point: ");} // input first point if(i==1){printf("\n Please enter your Finishing point: ");} // input first point } wrong=0; scanf("%16s", pos[i]); size_t x; flag = 0; for(x = 0; x < sizeof(place) / sizeof(*place); x ++) { if(strcmp(place[x+1], pos[i])==0) { point[i] = x; flag=1; } } if(flag==0) { printf("\n Invalid place name please re enter: "); i--; wrong=1; } }
This is how i call it
and this is my output:Code:places();
http://i57.photobucket.com/albums/g2...Untitled-2.jpg
it deosnt recognize any valid places which are input
thats what i have for a starter
ive been playing around with all sorts of ways but still i get nothing
it runs but when i put in a a valid place name it doesnt find itCode:char 2points( char place[11][11], int point[2], char pos[2][16]) { int x, wrong, flag for(i=0;i<2;i++) // loops round twice allowing the input of 2 points { if(wrong!=1) // if wrong is 0 it will out put the following { if(i==0){printf("\n Please enter your Start point: ");} // input first point if(i==1){printf("\n Please enter your Finishing point: ");} // input first point } wrong=0; // set wrong to 0 scanf("%16s", pos[i]); flag = 0; // sets flag to 0 so place is invalid until found for(x = 0; x < sizeof(place); x ++) { if(strcmp(place[x+1], pos[i])==0) { // place found point[i] = x; // point at position i is set to the value of x flag=1; //sets flag as 1 because its a valid place } } if(flag==0) // place not found { printf("\n Invalid place name please re enter: "); i--; // decrements i by 1 sooo it will loop round again wrong=1; // sets wrong to 1 so the ask for start or finsh point is not asked for again } } }
sooo far for the method i have just put it in like this and well called upon it
and well im getting no strcmp and anything it wont see valid place names anyone have any reading materialCode:void places(char pos[2][16], int point[2], char place[11][11]) { int i, x, wrong, flag; for(i=0;i<2;i++) // loops round twice allowing the input of 2 points { if(wrong!=1) { if(i==0){printf("\n Please enter your Start point: ");} // input first point if(i==1){printf("\n Please enter your Finishing point: ");} // input first point } wrong=0; scanf("%16s", pos[i]); size_t x; flag = 0; for(x = 0; x < sizeof(place) / sizeof(*place); x ++) { if(strcmp(place[x+1], pos[i])==0) { point[i] = x; flag=1; } } if(flag==0) { printf("\n Invalid place name please re enter: "); i--; wrong=1; } }