User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 422,558 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,691 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums

C Program where gets(), getchar(), are not working.

Join Date: May 2007
Location: Melbourne
Posts: 12
Reputation: brightmohan is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
brightmohan brightmohan is offline Offline
Newbie Poster

News Re: C Program where gets(), getchar(), are not working.

  #8  
May 5th, 2007
Here is the SAMPLE.C where gets() works absolutely fine. I dont understand why it isnt working in PROGRAM.C


  1.  
  2. #include<errno.h>
  3. #include<stdio.h>
  4.  
  5. int getline(char line[], int max)
  6. {
  7. int nch = 0;
  8. int c;
  9. max = max - 1; /* leave room for '\0' */
  10.  
  11. while((c = getchar()) != '\0')
  12. {
  13. if(c == '\n')
  14. break;
  15.  
  16. if(nch < max)
  17. {
  18. line[nch] = c;
  19. nch = nch + 1;
  20. }
  21. }
  22.  
  23. if(c == EOF && nch == 0)
  24. return EOF;
  25.  
  26. line[nch] = '\0';
  27. return nch;
  28. }
  29.  
  30.  
  31. #include <stdio.h>
  32.  
  33. extern int getline(char [], int);
  34.  
  35. main()
  36. {
  37. char line[256];
  38.  
  39. printf("Your names");
  40. getline(line,256);
  41. //while(getline(line, 256) != '\0')
  42. //
  43. printf("you typed \"%s\"\n", line);
  44.  
  45. return 0;
  46. }

I tired the solution posted by geek ANCIENT DRAGON. It is not working too....:
  1. char line[100];
  2. fgets(line,sizeof(line),stdin);
You have to let it all go Neo! Fear, Doubt, Disbelief!
Reply With Quote  
All times are GMT -4. The time now is 1:15 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC