Hi to everyone!
I have a problem with the following code. Can someone please point to me the error?
#include <stdio.h>
struct network{
char *name;
}network1;
int counter=0;
main()
{
void add_network();
add_network();
printf("You typed: %s\n", network1.name);
printf("counter is %d\n", counter);
}
void add_network()
{
char network_name[150];
puts("Give me the name: ");
gets(network_name);
network1.name=network_name;
printf("You typed: %s\n", network1.name);
counter=1;
printf("counter is %d\n", counter);
}
The problem is that the printf in the add_network function types correctly the input name, but the printf in main types jumbling characters. counter is typed correctly twice.