Open file in C

Asked

Viewed 778 times

-1

I wonder how I do to open a file in C (Open even, as if I had double-click), because the way I did, the program says that the file was opened, but it is not actually opened.

If the C language can’t do that, what language can I use?

Code:

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

int main(int argc, char *argv[])
{

  FILE *arquivo = fopen("c:\\eu.txt", "r");// testa se o arquivo foi aberto com sucesso

  if(arquivo != NULL)
    printf("Arquivo foi aberto com sucesso.");
  else
    printf("Nao foi possivel abrir o arquivo.");

  printf("\n\n");
  system("PAUSE");
  return 0;
}
  • What do you mean, double-click? You want to upload the file contents or you want to display the file contents with the file manager of that particular file type?

  • If the message "File opened successfully" appears then it is open. If in addition you want to display the contents of this file then you will have to include in your program the appropriate commands for this and, at the end, do not forget to close the open file.

1 answer

0

In fact, using the fopen, you will have a pointer to the file, so you can work with the contents of that file (read and write to the file, for example).

If you want to open the file with the default application, let’s assume a Notepad, you can use the functions execl or system.

Currently I can not test them in windows, but I think it should work too.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.