#include<stdio.h>
#include<conio.h>
void main(){
struct rtu{char[10] name;}rty1[10];
scanf("%s",&rty1[0].name[0]);
printf("%s",rty1[0].name[0]);
getch();
}
now listen in output screen i am getting error -
m termination with a arrow shaped figure
please help guyz
Hey there prince,
Just went over your code... Even though your program will compile, it's best practice making your main sub an integer return function.
int main()
{
printf("Hello world!\n");
return 0;
}
I have also noticed you did not declare your "name" array correctly. The appropriate syntax is:
char name[10];
When getting input from the user you are trying to store it at the memory address which will not be needed. Access the variable directly would be more efficient for this one.
You also seem to be trying to store the inputted text into "name" position 0, which wouldn't work out too well. Instead think of it as a single variable just storing a variable of 10 characters.
scanf("%s", rty1[0].name);
I have no idea why you using the getch() function, but here is the revised code that works. This is based upon the code you gave and has just been fixed to compile properly.
#include <stdio.h>
#include <conio.h>
int main()
{
struct rtu
{
char name[10];
} rty1[10];
scanf("%s", rty1[0].name);
printf(rty1[0].name);
getch();
return 0;
}
I can't give you an exact reason why your program was not compiling properly without exact error codes. But my guess is that your syntax was wrong and you weren't declaring variables correctly... If you give us more information on exactly what it is you wan't to do, it will be easier to aid you.
Peace Out