Having trouble with structures. How do i declare this? I need to d the following:
Your function will return an integer.
- Your function should only accept one argument (an array).
- Your function will ask the user for the number of characters that will be inputted. Then, inside your function, you will check if this value is greater than or equal to 70. If the values is greater than or equal to 70, you will print out an error message and return 1. Otherwise, you will use a loop to scan the characters and return 0.
#include <stdio.h>
struct info {
char name[70];
char lastname[70];
char address[70];
};
void printarray(char name[]) {
int i;
int number;
printf("How many characters will be inputted? \n");
printf("It cannot be more than 70!\n");
scanf("%d", &number);
printf("What is your name? \n");
for(i=0; i<number; i++) {
scanf(" %c", &info.name[i]);
}
return;
}
int main() {
struct info name;
return 0;
}
scanf(" %d", &int);
for the same reason The way to fix it is to make a variable ofstruct info
type and then use that in the scanf call. You could even call it info (but I wouldn't - imagine the confusion that would create!) – Jerry Jeremiahscanf (" %c",...)
in a loop to collect characters in the first place? Why not callscanf (" %70s",...)
instead and then the user doesn't need to say how many characters they are going to put in. – Jerry Jeremiahinfo
is not the name of a type.struct info
is the name of a type. – Keith Thompson