Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <conio.h>
  5.  
  6. //define what i need
  7. #define MAXNUM 2
  8.  
  9. //define struct
  10. typedef struct stud{
  11.     char name[20];
  12.     int age[10];
  13.     int nrm[10];
  14.     char adrs[30];
  15. } L_stud;
  16.  
  17. //other global variables
  18. L_stud list[MAXNUM];
  19.  
  20.  
  21. //function prototypes
  22. void read();
  23. char *check_name(char name[20])
  24. {
  25.     char *new_name = (char*) malloc(sizeof(char)*20);
  26.     new_name[0] = '\0';
  27.     int i = 0;
  28.     printf("%d\n", strlen(name));
  29.  
  30.     for( i = 0; i < strlen(name); i++)
  31.     {
  32.         //printf("test");
  33.         if(isalpha(name[i]))
  34.         {
  35.             strcat(new_name, 'a');
  36.         }
  37.         printf("%s\n",new_name);
  38.     }
  39.     printf("exit");
  40.     return new_name;
  41. }
  42.  
  43.  
  44. int main()
  45. {
  46.     char name[] = "Geor4gi/0";
  47.    // check_name(name);
  48.    printf("before");
  49.     char* s = check_name(name);
  50.     printf("%s",s);
  51.     printf("after");
  52.  
  53.  
  54.     int choice = -1;
  55.  
  56.     printf("Make a choice from below:\n 1.Read \n 2. \n 3. \n 4. \n 5.Exit\n ");
  57.     scanf("%d", &choice);
  58.  
  59.     while(choice)
  60. {
  61.         switch(choice){
  62.         case 1:
  63.             read();
  64.             break;
  65.         case 2:
  66.  
  67.             break;
  68.         case 3:
  69.  
  70.             break;
  71.         case 4:
  72.  
  73.             break;
  74.         case 5:
  75.             exit(0);
  76.             break;
  77.         default:
  78.             printf("Error! Wrong choice.\n");
  79.     }
  80.     printf("Make a choice from below:\n 1. \n 2. \n 3. \n 4. \n 5.Exit\n ");
  81.     scanf("%d", &choice);
  82. }
  83.  
  84.  
  85.  
  86. }
  87.  
  88.  
  89. void read(){
  90.     FILE *fp = fopen("data.in", "r");
  91.  
  92.     int i;
  93.     char single_line[50];
  94.     char sep[2] = ",";
  95.     char *token;
  96.  
  97.     while (!feof(fp))
  98.     {
  99.         fgets(single_line, 50, fp);
  100.  
  101.         token = strtok(single_line, sep);
  102.  
  103.         while (token != NULL)
  104.         {
  105.             printf("%s\n", token);
  106.             token = strtok(NULL, sep);
  107.         }
  108.  
  109.  
  110.  
  111.     }
  112.  
  113.     fclose(fp);
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement