Last edited by fortune2k; 04-04-2008 at 09:51 AM.
Mats, Patience not deniable. Statement made pertaining to over all of posts. Talented - yes, a little abrasive on some responses - yes. Please understand this is not an attack. It's a matter of seeking improvement on information transfer. It was something that needed to be said. Others on this forum would have loved to present what was said, but they do not post in fear of possible reduction in information. Please note that it goes without saying that there are allot of members on this board that do appreciate the contributions that you, Elysia, and all others who know who they are provide. All members on this forum should receive positive direction at all times.
right i have replaced cities with place and the validation is ok if i put a invalid place in it asks for re entry
however the distances are incorrect
http://i57.photobucket.com/albums/g2...Untitled-1.jpg
the place names in the txt file : ( the - is included as a place name to but doesnt need to be searched for )
Code:- London Glasgow Birmingham Manchester Luton Derby Poole Stafford Stoke Cardiff
Last edited by fortune2k; 04-04-2008 at 10:28 AM.
It's probably easiest to just skip the first item on the cities row, by adding a dummy fscanf() before the for-loop that reads the city names.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
i think ive cracked it still testing this is what ive got
Code: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; }
x+1 pushes the array up 1 so it forgets bout -
sorry for poor formatting
what you think outputs seem good ect
anyone know why i am expierencing do i need a return? i am really confused
Last edited by fortune2k; 04-04-2008 at 01:53 PM.
What is your function supposed to do? Does it make sense to return something?
I can't say for sure if you do or don't - it all depends on what you actually need it to do.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
well i use this twice
i just want it in a method so i can just call upon it twice i have a book here on methods but its not really saying muchCode: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; }
i think if i have to return somthing it will probs be the point array
Pedantery: Since this is not C++, and your code consequently isn't in a class, it's called a function, not a method.
The general way to create a function from some code that is part of another function involves something like this:
* write a new function that is empty inside. E.g.:
* mark the code you want to move to a function (just the one portion of code, if it happens to be there multiple times)Code:void func() { }
* cut the code (e.g. ctrl-X in Windows type machines).
* paste it into the new function, between the braces.
* fix up indentation.
* Introduce any variables and parameters necessary to the new function.
* write calls to the function where the code used to be.
* replace any other instances of the code with calls.
* Compile, fix any errors/warnings, recompile, <repeat as needed>
* Run the code, fix any bugs, <repeat as needed>
Job done.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
lol i get mixxed from methods and functions i think its coz im doin java 2 ok haha lol uve simply expliand how to do them in a few lines where as a book just rambles on thankyou i shall attempt this now
right im using
program runs however if i was to put in London as a place which is a valid place it doesnt recognize it i call upon the function "void places()"Code:void places() { }
You presumably will need something inside the braces to make that function do anything other than waste a few nanoseconds of time (assuming the compiler doesn't remove it all together).
And if you pass arguments to a function, you need to specify the function parameters, of course.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
welll earlier i was messing around with stuff like
but i dont really understand functions well sooo it was really guessing messing aroundCode:int places(char pos[2][16], char place[11][11], int point[2]) { }