Advertisement
Blizzardo1

CardCreator.c

May 6th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. FILE *_file;
  5. char name[30];
  6. char email[30];
  7. char telephone[12];
  8. char city[30];
  9. int count;
  10.  
  11. void replstr(char s[], char chr, char newchar) {
  12.     int i = 0;
  13.     while(s[i] != '\0') {
  14.         if(s[i] == chr)
  15.             s[i] = newchar;
  16.         i++;
  17.     }
  18. }
  19.  
  20. int main (void) {
  21.     _file = fopen("X:\\Your\\File\\Path\\Here.txt", "w");
  22.     if(_file == NULL){
  23.         printf("ERROR: Failed to open File for writing!");
  24.         return -1;
  25.     }
  26.  
  27.     printf("How many cards do you want to create? ");
  28.  
  29.     scanf("%d", &count);
  30.     printf("Creating %d cards\r\n", count);
  31.    
  32.     for(int i = 0; i < count; i++) {
  33.         printf("[%d] Name, Telephone, Email, City: ", i + 1);
  34.         scanf("%s %s %s %s", name, telephone, email, city);
  35.         replstr(name, '_', ' ');
  36.         replstr(name, '/', ',');
  37.         replstr(city, '_', ' ');
  38.         replstr(city, '/', ',');
  39.        
  40.         fprintf(_file, "%s, %s, %s, %s\r\n", name, telephone, email, city);
  41.     }
  42.  
  43.     printf ("Done! Closing out now!");
  44.  
  45.     fclose(_file);
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement