Code should be written in C Write a program that allows the user to enter data i
ID: 3818128 • Letter: C
Question
Code should be written in C
Write a program that allows the user to enter data into a form. The program should use character graphics and capabilities provided by the curses library. The program should display the prompts of the form continuously in the same positions (the specific prompts and positions are at the discretion of the programmer). After each keypress by the user, the data entered into the form should be updated and displayed. The fields of the form should include the first name, last name, and street address for a person. The two name fields should be limited to 20 characters, the street address field should be limited to 30 characters. Pressing the [ENTER] key should cause the cursor (current point of data entry) to jump to the first character in the next field. If the current field is the street address, then pressing [ENTER] should cause the program to report the entered data and then exit. Optional: Pressing the backspace key should allow the user to delete the last character entered in the current field.Explanation / Answer
#include <stdio.h>
#include <String.h>
struct data
{
char fname[50],lname[50],street[100];
};
main()
{
struct data x[100];
char ch='y';
int count=0,st1,st2,i;
char fname1[50],lname1[50],street_add[100];
do
{
int op;
printf("1.user data() 2.display() ");
scanf("%d",&op);
if(op==1)
{
while(1)
{
printf("Enter Fist Name ");
scanf("%s",&fname1);
printf("Enter Last Name ");
scanf("%s",&lname1);
st1=strlen(fname1);
st2=strlen(lname1);
if(st1+st2<=20)
{
strcpy(x[count].fname,fname1);
strcpy(x[count].lname,lname1);
break;
}
else{
printf("Please enter name must be 20 litters of only ");
}
}
while(1)
{
printf("Enter street address ");
scanf("%s",&street_add);
if(strlen(street_add)<=30)
{
strcpy(x[count].street,street_add);
break;
}
else
{
printf("please enter address must be 30 letters only ");
}
}
count++;
}
else if(op==2)
{
if(count==0)
printf("DATA IS EMPTY ");
else
{
printf("FIST NAME LAST NAME STREET ADDRESS ");
for(i=0;i<=count;i++)
{
printf("%s %s %s ",x[i].fname,x[i].lname,x[i].street);
}
}
}
else
{
printf("YOU ARE ENTRING OPTION IS WORING ");
}
printf("DO YOU WANT TO CONTUE ONE MORE (Y/N) ");
ch=getch();
}while(ch=='y');
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.