Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct Email {
- char * name;
- char * domain;
- } email_list[10];
- char aaa[10];
- int main(){
- char buf[1024];
- fgets(buf,1024,stdin);
- int e_idx=0;
- char * res = strtok(buf,"@");
- while (1){
- if (res == 0){
- break;
- }
- printf("name %s\n",res);
- email_list[e_idx].name = malloc(strlen(res)+1);
- strcpy(email_list[e_idx].name,res);
- res = strtok(NULL,";");
- if (res == 0){
- break;
- }
- printf("domain %s\n",res);
- if (e_idx !=3){
- email_list[e_idx].domain = malloc(strlen(res)+1);
- }
- else{
- email_list[e_idx].domain = malloc(16);
- }
- strcpy(email_list[e_idx].domain,res);
- e_idx++;
- if (e_idx==10)
- break;
- res = strtok(NULL,"@");
- }
- printf("Parsed %d emails\n",e_idx);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment