switch and string copy problems
How do i change an int to a char when using a switch and the string copy command
the way im doing it isnt working
everything is declared right. What i want is when 1 is pressed it prints Boarding at tescos
printf("\nWhat is your boarding stop number: ");
printf("Boarding at %s", stop_name);
case 1: strcpy(stop_name,"Tescos");
what was the error you get?
do you declare it the right place?
This is the example answer...I declared the string variable as global variable. but this is not quite good in realily...
#include <string.h> /* need to use string library */
#define SIZE 200
/* to up readable */
#define TESCOS 1
#define KUALA_LUMPUR 2
#define TOKYO 3
char stop_name[SIZE]; /* global variable */
printf("What is your boarding stop number?\n");
printf("Boarding at %s \n",stop_name);
void BusStop(int number)
case TESCOS: /* for choice 1 */
case KUALA_LUMPUR: /* for choice 2 */
strcpy(stop_name, "Kuala Lumpur");
strcpy(stop_name, "No name!");
/* program end */
Your bug is right here:
You should be passing the address of the second argument (boarding) to the scanf function, so that it can alter the value of the variable boarding.