-2

I wrote this :

#include <stdio.h>
#include <stdlib.h>

FILE * fp;

char Name[101], Address[101], Email[101], Gender[9], k;

int Phone[10];

int main()
{
    fp = fopen("Mallon.txt", "a");
    fflush(stdin);
    printf("Name:");
    fgets(Name, sizeof(Name), stdin);
    fflush(stdin);
    printf("Address:");
    fgets(Address, sizeof(Address), stdin);
    fprintf(fp, "%s %s", Name, Address);
    return(0);
}

And it is printing in the file this:

Name
Address

But i want:

Name Address

What should I do to print in the file the selected name and address in the same line. I think that fprintf when I press enter to write the address sents the address in the next line.

wohlstad
  • 3,689
  • 2
  • 9
  • 24
  • How told these new coders to use initialize variables in global scope? I have seen many `New contributors` using global variables in C. `fflush(stdin);` is the worst thing ever – Darth-CodeX May 14 '22 at 12:26

0 Answers0