lol my instructer will say look at the lecture notes and well theres nothing on there bout what im stuck on lol i aint the best at C but its giving me headaches but im gonna try figure this out
lol my instructer will say look at the lecture notes and well theres nothing on there bout what im stuck on lol i aint the best at C but its giving me headaches but im gonna try figure this out
right i have managed to get it to put out an error message but having problems with if its true setting the point for the places.
i decided to use flag as a int and set it to 1 or 0.
this is what i have
output :Code:wrong=0; scanf("%16s", pos[i]); size_t x; flag = 0; for(x = 0; x < sizeof(cities) / sizeof(*cities); x ++) { if(!strcmp(cities[x], pos[i])==0){point[i] = x;} // assigns point a number depends what place name was enterd else {flag=1;} } if(flag==0) { printf("\n Invalid place name please re enter: "); i--; wrong=1; }
http://i57.photobucket.com/albums/g230/fortune2k/dd.jpg
You should get yourself a debugger. Perhaps Visual Studio.
And note that this line
Looks suspicious.Code:if(!strcmp(cities[x], pos[i])==0){point[i] = x;}
Strcmp returns 0 if the strings match. Yet the "!" operator inverses the result so if strcmp returns 1, it will be changed to 0 before the comparison. Likewise, if it returns 0 or < 0, it will be 1 before the compare. Watch out.
im using dev c++ maybe i should change sooo what shall i change it to then i tryed !=0 and taking it out completly and well it doesnt work
Remove the "!".Code:if(strcmp(cities[x], pos[i])==0){point[i] = x;}
Strcmp returns 0 if the strings are equal.
I suggest you get a debugger and learn basic debugging facilities. Stepping through code and checking the value of variables.
Basic stuff. There will come a day when you need a debugger.,
How is it so?Likewise, if it returns 0 or < 0, it will be 1
outputCode:#include<stdio.h> int main() { printf("%d %d %d\n", !(-1), !0 , !1); return 0; }
Code:0 1 0
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
values that are < 0 as well as the values that are >0 all evaluate to true
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
ok uve confused me now
Brain error!
The area in the brain where the information was stored has been short circuited, so it fell back on trying to guess with the information it had which obviously turned out wrong!
Fortune: Don't use !strcmp, just do strcmp and compare to 0 to see if the strings match.
yes i understand that i mean how to have it set in the if statement
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
right this is what i have
i still get no distance output its still the same asCode:scanf("%16s", pos[i]); size_t x; flag = 0; for(x = 0; x < sizeof(cities) / sizeof(*cities); x ++) { if(!strcmp(cities[x], pos[i])==0){point[i] = x;} // assigns point a number depends what place name was enterd else if(!strcmp(cities[x], pos[i])!=0) {flag=1;} } if(flag==0) { printf("\n Invalid place name please re enter: "); i--; wrong=1; }
http://i57.photobucket.com/albums/g230/fortune2k/dd.jpg
You didn't change what they told you to change. Start there.