Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple problem 1

Status
Not open for further replies.

TFfan

Programmer
Joined
Jan 18, 2002
Messages
192
Location
CA
I'm taking an intro course to programmign in C. My current assignment is pretty straight forward. I have to read two sets of integers compare them and find the lesser value. In other words, it's a vacation cost calculator designed to find which hypothetical trip is cheaper.

I'm still a little shakey with functions and global vs local variables so bear with me. I've met with a problem: the two trips I'm comparing are Australia and Europe. I have to use functions to calculate the costs and display the output values.

I thought I'd declare a global string to represent the locations. At first its value would be "Europe" and when it returns from the function, I'd set it to "Australia" and display its output.

I get an error, and I don't know how to resolve it. the string is named "dest" and I'm trying to use the command: "dest="Australia". Any help or pointers are appreciated.


#include <stdio.h>

char dest[9]=&quot;Europe&quot;;

void calculateExpenses(); /* the function declaration */
void PrintResults();

main() {
int etik, eexp, ehot, efood, atik, aexp, ahot, afood;

printf(&quot;Enter the ticket, traveling, hotel and dining costs separated by a space for Europe: \n&quot;);
scanf(&quot;%d %d %d %d&quot;, &etik, &eexp, &ehot, &efood);

printf(&quot;Enter the ticket, traveling, hotel and dining costs separated by a space for Australia: \n&quot;);
scanf(&quot;%d %d %d %d&quot;, &atik, &aexp, &ahot, &afood);


calculateExpenses(etik, eexp, ehot, efood); /* the function call */

calculateExpenses(atik, aexp, ahot, afood); /* the function call */

return 0; /* exit main function */
}

void calculateExpenses(int w, int x, int y, int z) { /* the function definition */
int travel = (int) (w + x); /* coersion */
int board = (int) (y + z);
int total = (travel + board);
PrintResults(travel, board, total);
}
void PrintResults(int t, int b, int tot){ /* the function definition */
printf(&quot;Travelling Expenses for %s are %d\n&quot;, dest, t);
printf(&quot;Boarding Expenses for %s are %d\n&quot;, dest, b);
printf(&quot;The total expenses for %s are %d\n&quot;, dest, tot);
}
 
Wonder what the error output is ?
I'll guess that dest[9] ought to be dest[10]
and using stcpy it'll be null-terminated ie :
strcpy(dest,&quot;Australia&quot;);
HTH ;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Thanks for the quick reply, but I get an error message that might as well be greek for all the good it does me. I put strcpy(dest,&quot;Australia&quot;); in between my function calls.

I apologize for my ignorance--I'm sure it's a simple concept.


ld32: ERROR 33 : Unresolved text symbol &quot;strcopy&quot; -- 1st referenced by f2.o.
Use linker option -v to see when and which objects, archives and dsos are loaded.
ld32: INFO 152: Output file removed because of error.
(16)% cc f2.c
ld32: ERROR 33 : Unresolved text symbol &quot;stcopy&quot; -- 1st referenced by f2.o.
Use linker option -v to see when and which objects, archives and dsos are loaded.
ld32: INFO 152: Output file removed because of error.
(17)% cc f2.c
ld32: ERROR 33 : Unresolved text symbol &quot;strcopy&quot; -- 1st referenced by f2.o.
Use linker option -v to see when and which objects, archives and dsos are loaded.
ld32: INFO 152: Output file removed because of error.
 
STRCPY - there's no 'o' - its not strcopy
;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
LOL, the curse of being a former English major! Thanks for your help (and patience).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top