so I'm relatively a beginner at C and I'm working for a code about account structs just for fun.
Also I'm new at stack overflow.
I am making a function named accN() where they use the printf and gets to input username, password, and email.
I'm guessing there is a lot of errors in the code.
Anyway the code:
#include <stdio.h>
#include <string.h>
struct account{
char accun[30];
char accpw[30];
char accem[30];
};
struct account accN(){
struct account temp;
char temps[3][30];
printf("username:\n");
gets(temps[0]);
for (i = 0; i < sizeof(temps[0]); ++i){
if (temps[0][i] == ' '){
for (j = i; j < sizeof(temps[0]); ++j){
temps[0][j] = temps[0][j+1];
}
}
}
printf("password:\n");
gets(temp.accpw);
for (i = 0; i < sizeof(temps[1]); ++i){
if (temps[1][i] == ' '){
for (j = i; j < sizeof(temps[1]); ++j){
temps[1][j] = temps[1][j+1];
}
}
}
printf("email:\n");
gets(temp.accem);
for (i = 0; i < sizeof(temps[2]); ++i){
if (temps[2][i] == ' '){
for (j = i; j < sizeof(temps[2]); ++j){
temps[2][j] = temps[2][j+1];
}
}
}
strcpy(temp.accun, temps[0]);
strcpy(temp.accpw, temps[1]);
strcpy(temp.accem, temps[2]);
return temp;
}
int main(){
struct myacc = accN();
}