question in c

This is a discussion on question in c within the C Programming forums, part of the General Programming Boards category; hi all i have a qestion in previus question exam and i cannot soluation it can any one help me ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    6

    Unhappy question in c

    hi all

    i have a qestion in previus question exam
    and i cannot soluation it


    can any one help me on it


    http://www.phroon.com/up/file1/1111122.JPG

    the question in the picture
    plz dont late

    thanks allllll
    Last edited by Salem; 08-19-2007 at 04:06 AM. Reason: Remove centre tags

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    No, more like you have a question due for homework. Why is your post centered?

    Hint: research fprintf and fgets and sscanf, also look around the FAQ.

    The logic from there is simple,
    read each line in a loop, scan it, equate the tax from the salary, write the new record into another file.

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    6
    ohh ..
    i dont know c programming

    plz help me
    plzz

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,743
    i dont know c programming
    Time for you to learn then. Check out the homework policy.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Looks like someone slacked off in class or didn't go to the lectures, there's no way you'd be asked to do something you hadn't been taught.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,307
    Quote Originally Posted by zacs7 View Post
    there's no way you'd be asked to do something you hadn't been taught.
    In classrooms that's usually true.

    For a lot of jobs in the real world, some problem solving skills and adaptability are expected. In other words, being able to find a solution to a problem without someone to teach you how to do it. Those who can't solve problems in a classroom will fail dismally in such real world situations.

  7. #7
    Registered User
    Join Date
    Aug 2007
    Posts
    6
    ok


    thanks

    but iam not have the answer yet !!
    ok
    byy

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    You do have the answer, no-one is going to do the work for you.

  9. #9
    Registered User
    Join Date
    Apr 2007
    Posts
    112
    since im newb in c i gues i can try help him (since i will learn something too ).

    at first we need to work with files so :
    tutorial about files

    then we shlould read what we was told by the elders ..

    sscanf
    fprintf

    i guess you know how to do the rest .

    P.s.
    read about structs
    why Gaos didn't had a wife ?
    http://bsh83.blogspot.com

  10. #10
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Lol, it's kind of obvious it's homework, but I must point out some lecturers(ignoramuses) will set assignments and hint on how to start the assignment while making reference to implementing C features that have not been taught yet...nice one...

    That way when you start using stuff you haven't been taught and something goes wrong, then you have to start rewriting your code again with stuff you know and there goes wasted hours when you could have spent it on some other subject or eating a peanut butter and jelly sandwich.

  11. #11
    Registered User
    Join Date
    Aug 2007
    Posts
    6

    answer

    hi

    i have the answer
    but i will ask if it write or wrong

    answer:

    Code:
    #include<stdio.h>
    #include<conio.h>
    FILE *infile,*outfile;
    struct my_rec{char name[10];
                   int id;
                   int salary;};
    
    typedef struct my_rec test;
           
    void  main()
            {
            int i,j;
            double avg,sum=0;
            test sample[10];
    //clrscr();
            infile=fopen("c:\\aa.dat","r");
            outfile=fopen("c:\\out.dat","w");
       i=0;
       while (!feof(infile))
    
    {
    
       fscanf(infile,"%s",&sample[i].name);
       fscanf(infile,"%d",&sample[i].id);
       fscanf(infile,"%d",&sample[i].salary);
       i++;
       }
       for(j=0;j<i;j++)
       {fprintf(outfile,"%d name= %s id = %d salary = %d tax = %d\n",j+1,
       sample[j].name, sample[j].id, sample[j].salary, (sample[j].salary*17)/100);}  
       }

  12. #12
    Registered User
    Join Date
    Aug 2007
    Posts
    6
    write or wrong ??????!!!!!!!!!!!!!!!

  13. #13
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Depends on how you define right or wrong, read at least the following:
    http://faq.cprogramming.com/cgi-bin/...&id=1043284376 (void main)
    http://faq.cprogramming.com/cgi-bin/...&id=1043284351 (feof in loops)

    You should be checking if you actually open the file, (fopen returns NULL if it fails), and you should be closing it at the end.
    Oh and don't use conio.h.

    Consider my suggestion, I didn't say it for fun - question in c
    Infact you seem to have ignored 99&#37; of the posts in this thread.

    I'm going to say wrong, but close - well not really close, but the idea is there.

  14. #14
    Registered User
    Join Date
    Aug 2007
    Posts
    6
    okay ..
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21