c - wrapper function in fgets() -


i seek expert in c programming. in advance.

example:

#include <stdio.h> #include<stdlib.h> #include<ctype.h> void main() { char name[100][52],selection[2]="y"; int x,nname=1; float sales; { printf("enter name: "); fflush(stdin); fgets(name[nname],51,stdin); // need put wrapper in here printf("enter sales: "); scanf("%f",&sales); if (sales<1000) printf("%s\tgood\n",name[nname++]); else printf("%s\tvry good\n",name[nname++]); printf("enter name?(y/n)"); fflush(stdin); fgets(selection,2,stdin); *selection=toupper(*selection); }while(nname<=100 && *selection=='y'); for(x=1;x<nname;x++) printf("%s\n",name[x]); // want print result without(newline) /n printf("end\n"); system("pause"); } 

how print names without being separated new lines?

just use

printf("%s ", name[x]); 

instead of

printf("%s\n", name[x]); 

the \n character creating new lines.

edit

fgets apparently reads newlines buffer - can strip newline with

name[nname][strlen(name[nname])-2] = '\0'; 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -