Pls help me with this Struct function

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2006
Posts: 251
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Pls help me with this Struct function

 
0
  #11
Sep 28th, 2008
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.
"Any fool can know, point is to understand"
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 20
Reputation: J-son is an unknown quantity at this point 
Solved Threads: 0
J-son's Avatar
J-son J-son is offline Offline
Newbie Poster

Re: Pls help me with this Struct function

 
0
  #12
Oct 3rd, 2008
Thanks all of u
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 113
Reputation: ahamed101 is an unknown quantity at this point 
Solved Threads: 14
ahamed101's Avatar
ahamed101 ahamed101 is offline Offline
Junior Poster

Re: Pls help me with this Struct function

 
0
  #13
Oct 5th, 2008
Originally Posted by J-son View Post
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?
regards,
Ahamed.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 3
Reputation: abhijeetcn is an unknown quantity at this point 
Solved Threads: 0
abhijeetcn abhijeetcn is offline Offline
Newbie Poster

Re: Pls help me with this Struct function

 
0
  #14
Oct 6th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC