Thread: Is there away to call a next program C program and match user input with the current

  1. #1
    Registered User
    Join Date
    Dec 2015
    Posts
    6

    Is there away to call a next program C program and match user input with the current

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main()
    {
        FILE *fptr;
        char ans;
        char buff[100];
        char name[200];
        char address[500];
        char telephone[17];
        char sex[23];
        char dateOfBirth[100];
        unsigned char jobDescription[2000000];
        float amountOfMoney,discount,d_price;
        int x,y;
        time_t now = time(0);
    
    
    
    for(x = 1; x<=1000;x++){
    printf("\nENTER ALL CUSTOMER INFORMATION BELOW.\n");
    fptr = fopen("C:\Customer's Info.txt", "a+");
    printf("\n\nPlease Enter the Customer's Name: ");
    fflush(stdin);
    scanf(" %[^\n]", &name);
    fprintf(fptr,"Customer Number: %i\n",x);
    fprintf(fptr,"Customer Name: %s\n",name);
    printf("\nPlease Enter Customer's Gender: ");
    fflush(stdin);
    scanf("%[^\n]",&sex);
    fprintf(fptr,"Customer Gender: %s\n",sex);
    printf("\nPlease Enter Customer's Date Of Birth: ");
    fflush(stdin);
    scanf("%[^\n]",&dateOfBirth);
    fprintf(fptr,"Customer D.O.B: %s\n",dateOfBirth);
    printf("\nPlease Enter Customer's Current Address: ");
    fflush(stdin);
    scanf("%[^\n]",&address);
    fprintf(fptr,"Customer Address: %s\n",address);
    printf("\nPlease Enter Customer's Telephone Number: ");
    fflush(stdin);
    scanf("%[^\n]",&telephone);
    fprintf(fptr,"Customer PhoneNumber: %s\n",telephone);
    printf("\nPlease Enter The Customer's Job Description: ");
    fflush(stdin);
    scanf("%[^\n]",jobDescription);
    fprintf(fptr,"Customer Complaint: %s\n",jobDescription);
    printf("\nPlease Enter The Amount The Customer Paid: ");
    fflush(stdin);
    scanf("%f",&amountOfMoney);
    fprintf(fptr,"Money Paid By Customer: $%.2f\n",amountOfMoney);
    printf("\nIs %s Getting Any Discount? ",name);
    fflush(stdin);
    scanf(" %c",&ans);
    if(ans == 'y'|| ans == 'Y'){
    printf("\nEnter the Discount off in percentage (dont use %% just enter the digits): ");
    fflush(stdin);
    scanf("%f",&discount);
    d_price = amountOfMoney - (discount/100.00 * amountOfMoney);
    fprintf(fptr,"Customer Discount: %.2f%% off \nDiscounted Price: $%.2f \n", discount, d_price);
    }else{
    printf("\n");
    };
    strftime(buff,100,"%Y-%m-%d %H:%M:%S.000", localtime(&now));
    fprintf(fptr,"TimeStamp: %s\n\n\n",buff);
    fclose(fptr);
    }
    getchar(); return 0; }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,323
    Quote Originally Posted by Divulger
    Is there away to call a next program C program and match user input with the current
    You might want to elaborate on what you mean by that. It would also be a good idea to provide a bigger picture of what your program(s) is supposed to do.

    As for the program that you posted:
    • Break up your main function into smaller functions that do one thing and do it well.
    • Consider declaring a struct for customer information.
    • You made some pretty good effort at proper indentation, and that is great, but you could still be a little more consistent, e.g., within the body of the for loop.
    • Special characters can be written by preceding them with a backslash. Hence, it is incorrect to write "C:\Customer's Info.txt". You should escape the character: "C:\\Customer's Info.txt".
    • You should check the return value of fopen to ensure that it is not a null pointer before proceeding to read/write.
    • fflush is only defined by the standard for output streams and update streams for which the last operation was output, so be aware that fflush(stdin) results in undefined behaviour since stdin is an input stream (duh). Generally, you can either read line by line and then parse the lines read, or you can read and discard unwanted characters.
    • Be careful of buffer overflow: "%[^\n]" for scanf should specify the field width, e.g., "%199[^\n]".
    • Check the return value of scanf and other functions that read input.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2015
    Posts
    6
    i want to search in the txt output file based on previous history of the user input for a customer based on gender,name,and D.O.B. Next step is to make the C program open a next C program which should require a user password,user name,user gender,and date this must be matched to the first open program to create a user and give that user name to the txt file and give that txt file a password so only that user can access it when the txt is created.The created txt file shouldn't be able to be edited neither be copied anything goes wrong in the document it must only be corrected from the cli with a search and find option to the program which is a next C program specialized for searching and replacing user input within a specified file.

    So any help am just a beginner but my head hurts at night because i have too much crazy ideas its like am almost compelled to program and also to come up with problems which i cant even solve myself so if you understand what am saying just tell me if that's possible please.

    And also state if am dumb because i can only think about changing the future i need to know if am thinking good or bad why i choose C programming is because i heard it the hardest to master and me on the other hand love challenge so i want something that people call impossible to make it possible.

  4. #4
    Registered User
    Join Date
    Dec 2015
    Posts
    6
    altho am a beginner \\ doesnt work whenever i use it my txt document never gets created but still thanks for the heads up and am good at OOP never knew C has one i def have to go learn it well javascript and php me taught me OOP along with 14 tutorials of JAVA which i find lame.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,323
    Quote Originally Posted by Divulger
    \\ doesnt work whenever i use it my txt document never gets created
    A likely reason is that the root of the C drive requires administrator permission to create files (or write to files at that level), hence your attempt to create "C:\Customer's Info.txt" failed when you correctly used the string "C:\\Customer's Info.txt". You would probably need to run your program with administrator access, but instead of doing that, perhaps you should place the file in the current directory (where the executable program is located) or some other designated directory, e.g., "C:\\Divulger\\Customer's Info.txt". That "C:\Customer's Info.txt" apparently worked for you is probably because a file with some mangled name was created in the current directory.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C program does not take input from user
    By Izzy98 in forum C Programming
    Replies: 4
    Last Post: 11-06-2015, 03:26 PM
  2. Program to match strings from input to files using dfa
    By Praveena Rao K in forum C Programming
    Replies: 3
    Last Post: 09-04-2013, 07:11 AM
  3. Want User Input but Program Ends
    By completenewbieu in forum C Programming
    Replies: 5
    Last Post: 08-29-2011, 04:10 PM
  4. Replies: 3
    Last Post: 10-12-2010, 01:40 PM
  5. user input and program design
    By Chaplin27 in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2005, 08:53 AM