943,740 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1863
  • C RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Sep 28th, 2008
0

Re: Pls help me with this Struct function

Quote ...
I have seen "good advices" to read stdin char by char until '\n' or EOF occured. I think, it's a bad idea: there are situations when user/program dialog hangs.
Thats the only way which i can think off, which could be portable to certain extent. But as you say if it was used in some event driven cases then probably it might hang (Need to hit enter, since getchar is used!), if '\n' or EOF not found in the input buffer.

ssharish
Last edited by ssharish2005; Sep 28th, 2008 at 8:20 pm.
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Oct 3rd, 2008
0

Re: Pls help me with this Struct function

Thanks all of u
Reputation Points: 10
Solved Threads: 0
Newbie Poster
J-son is offline Offline
20 posts
since May 2008
Oct 5th, 2008
0

Re: Pls help me with this Struct function

Click to Expand / Collapse  Quote originally posted by J-son ...
Thanks very much for ur helps but sorry ... I don't get what u mean. I m just a beginner. Here I removed function and tested, it run, compiled but error with result.
What should I do? Thanks anyway.
  1. #include <stdio.h>
  2. int main( )
  3. {
  4. struct student
  5. {
  6. char name;
  7. char dep;
  8. char course;
  9. int roll;
  10. int year;
  11. };
  12. struct student d2[3];
  13. int i;
  14. printf("Enter Roll Number,Name, Department, Course, Year of Joining\n");
  15. for (i=0;i<=2;i++){
  16. scanf("%d %c %c %c %d",&d2[i].roll,&d2[i].name,&d2[i].dep,&d2[i].course,&d2[i].year);
  17. }
  18. for (i=0;i<=2;i++)
  19. printf("\nRoll Number:%d Name:%c Department:%c Course:%c Year of Joining:%d",d2[i].roll,d2[i].name,d2[i].dep,d2[i].course,d2[i].year);
  20. return 0;
  21. }
Is it resolved?
Reputation Points: 51
Solved Threads: 14
Junior Poster
ahamed101 is offline Offline
114 posts
since Jul 2008
Oct 6th, 2008
0

Re: Pls help me with this Struct function

you just have to make following change in your structure.....your progam will surely run....
you can use "getch();" to make output wait till you press any key...
it is included in <conio.h>

hope it will work....

  1. struct student
  2. {
  3. char name[10];
  4. char dep[10];
  5. char course[10];
  6. int roll;
  7. int year;
  8. };
Last edited by abhijeetcn; Oct 6th, 2008 at 5:36 am.
Reputation Points: 7
Solved Threads: 0
Newbie Poster
abhijeetcn is offline Offline
3 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: comparing a function with library power
Next Thread in C Forum Timeline: Problem related to c in looping





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC