Hello, my name is João, i'm from Portugal so forgive me in advance for any writing errors.
I have a piece of C code that I can't put it to work correctly and I was hoping you can help me on this.
The objective of this program is to have 2 generic function, one for reading integers and another for reading strings, both to be applied on many other functions each one with a different question.
Code:
#include <stdio.h>
int ler_int (){
int num;
scanf(" %d", &num);
return num;
}
char* ler_char (char *frase, int max){
fgets(frase, max, stdin);
return frase;
}
int le_nss (){
printf ("Qual o seu numero de segurança social?: ");
return ler_int();
}
char *le_nome(char *nome){
printf ("qual é o seu nome?: ");
int max = 100;
return ler_char(nome, max);
}
main(){
char id_nome[100];
int NSS = le_nss();
le_nome(id_nome);
printf("o seu numero de NSS é: %d\n", NSS);
printf("o seu nome é: %s\n", id_nome);
}
I'm learning about pointers and it's a little bit confusing for me the use of them so probably the problem lies in the incorrect use of pointers but I can't seem to figure it out.
Thanks for the help