C an ATM

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jerryandchandan
    New Member
    • Dec 2008
    • 6

    C an ATM

    hello. am new in this forum but i notice that u have dissucions about c so i am wondering if anyone can help me in doing an ATM program using file I/O. i know how to create a text file and use it but i dont know how to make it read one at a time. for example: this is my starting program.

    #include <stdio.h>

    int main()
    {
    FILE *customer_infor mation;
    char pin_number[4]={101,102,103,1 04};
    int test;
    customer_inform ation=fopen("cu stomer_informat ion.txt","w");
    if(customer_inf ormation==NULL)
    {
    puts("Error creating file");
    return (1);
    }

    for(test=0;test <4;test++)
    fprintf(custome r_information," %d\n",pin_numbe r[test]);
    fclose(customer _information);

    printf("Pin numbers:");
    for(test=0;test <4;test++)
    printf("\n%d\n" ,pin_number[test]);


    return 0;

    but i need this to read one number at a time like:
    printf("Enter your pin number:");
    the file contains: 101,102,103
    but i need it to read just 101
  • vmpstr
    New Member
    • Nov 2008
    • 63

    #2
    Your file contains

    101
    102
    103

    Then you can just use fscanf(infile, "%d", &first_pin); (or some other read-from-file function, coupled with string-to-integer conversion)

    Is that what you are asking?

    Comment

    • jerryandchandan
      New Member
      • Dec 2008
      • 6

      #3
      i would like to use char or has a string only and not int for the pin number. could i do that and now. please.

      Comment

      • vmpstr
        New Member
        • Nov 2008
        • 63

        #4
        ... and now.
        You can certainly do it at any point in time. Any book on C can help you read a C string (array of characters that is nul terminated) from a file.

        Comment

        • jerryandchandan
          New Member
          • Dec 2008
          • 6

          #5
          i have but i dont understand the concept

          Comment

          • vmpstr
            New Member
            • Nov 2008
            • 63

            #6
            You don't understand the concept of reading strings from file? What piece of code from your C book do you not understand in particular?

            Comment

            Working...