• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

not removing trailling new line character after first iteration from string got input from fgets.

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not removing trailling new line character after first iteration from string got input from fgets(s1, 26, stdin);
program is here :-
 
Rancher
Posts: 508
15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi rahul - it's because the scanf("%f" doesn't read the newline/return that you enter at the end of the balance value. So that ends up as input to the next fgets, which sees it as the end of its input. Thus it reads an empty string, without you apparently having entered anything.

I suggest using fgets for both. Eg. for the balance do something like
 
rahul vishwakarma
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot sir, I did as you said and problem is solved. I did like this :-
 
John Matthews
Rancher
Posts: 508
15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good.

One suggestion though - there is no need for all the malloc()s. They complicate the code, and they might fail (which you aren't testing for, but you should be). Just use arrays of char.
 
reply
    Bookmark Topic Watch Topic
  • New Topic