0

I have a program in C that changes a decimal number into a binary.

int main()
{
  int n, c, k;

  printf("Enter an integer\n");
  scanf("%d", &n);

  printf("%d in binary is:\n", n);

  for (c = 31; c >= 0; c--)
  {
    k = n >> c;

    if (k & 1)
      printf("1");
    else
      printf("0");
  }

  printf("\n");

  return 0;

}

It takes data from what I write in terminal but I would like it to get the data from integers.txt file, which is something like this:

101
34
-11
1,5
lorem ipsum
33.33333
10022

The program should get the integers from the txt file and perform an action to change them into the binary, and at the same time should warn that 1,5 or lorem ipsum are not integers, should not perfom the action on them but should continue to convert other integers. And I'm a bit stuck on how to properly get integers from .txt file and process convert action on them.

lepsztyk
  • 53
  • 2
  • 6

1 Answers1

0

You need to search concepts like file pointer and fopen. Those fopen has modes that lets you manipulate files for whatever mode you want(append,write,read) and their + forms .Also search for command arguments for inputing them via terminal. Pearson C is a good book for guide

paypaytr
  • 199
  • 1
  • 1
  • 12