Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define atoa(x,y) #x
- int main() {
- FILE * fp;
- char c;
- fp = fopen("1.txt", "r");
- int ck=0;
- int flag=1;
- char name[100],age[100],nation[100],work[100];
- int agee=0;
- int i=0;
- while ((c = getc(fp)) != EOF) {
- if(ck==11 && flag==1)
- {
- if(c=='.')
- {
- flag++;
- ck=0;
- name[i]='\0';
- i=0;
- }
- else
- {
- name[i] = c;
- i++;
- }
- }
- else if(ck==16 && flag==2)
- {
- if(c=='.')
- {
- flag++;
- ck=0;
- age[i]='\0';
- i=0;
- }
- else
- {
- age[i] = c;
- i++;
- }
- }
- else if(ck==20 && flag==3)
- {
- if(c=='.')
- {
- flag++;
- ck=0;
- nation[i]='\0';
- i=0;
- }
- else
- {
- nation[i] = c;
- i++;
- }
- }
- else if(ck==29 && flag==4)
- {
- if(c=='.')
- {
- flag++;
- ck=0;
- work[i]='\0';
- i=0;
- }
- else
- {
- work[i] = c;
- i++;
- }
- }
- else ck++;
- }
- fclose(fp);
- while(age[i])
- {
- agee = agee*10 + age[i]-'0';
- i++;
- }
- agee = 2019-agee;
- printf("%s\n%d\n%s\n%s\n",name,agee,nation,work);
- printf("\n");
- ck=0;
- int j=0;
- char mail[100];
- printf("Name: ");
- for(i=0;i<strlen(name);i++)
- {
- if(name[i]==' ')
- {
- ck=1;
- }
- else if(ck==1)
- {
- printf("%c",name[i]);
- mail[j] = name[i];
- j++;
- }
- }
- printf("\nAge: %d\n",agee);
- printf("Nationality: %s\n",nation);
- char str_age[100];
- sprintf(str_age, "%d", agee);
- for(i=0;str_age[i]!='\0';i++)
- {
- mail[j] = str_age[i];
- j++;
- }
- mail[j]=mail[0];
- j++;
- mail[j]='@';
- j++;
- mail[j]='g';
- j++;
- mail[j]='m';
- j++;
- mail[j]='a';
- j++;
- mail[j]='i';
- j++;
- mail[j]='l';
- j++;
- mail[j]='.';
- j++;
- mail[j]='c';
- j++;
- mail[j]='o';
- j++;
- mail[j]='m';
- j++;
- mail[j]='\0';
- printf("%s\n",mail);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement