C Portability on Linux

1

I'm starting to use Compilr and there they use Linux. I'm having some problems like for example printing a text file. Look at my program, it works on windows:

#include<stdio.h>
/*
escreva um programa que leia o nome de 10 pessoas e armaene esses nomes no arquivo de texto nomes.txt
*/

int main()
{
FILE *arquivo;
int i;
char nome[40], c;

arquivo=fopen("nomes.txt", "a");

printf("digite os 10 nomes:\n");

for(i=0; i<10; i++)
{
    gets(nome);
    fprintf(arquivo,"%s \n",nome);
}

fclose(arquivo);

arquivo=fopen("nomes.txt", "r+");

while((c=getc(arquivo))!=EOF)
    printf("%c",c);

return 0;
}

What's different about writing Linux and Windows so I can get started with Fedora.

    
asked by anonymous 28.10.2014 / 12:03

1 answer

2

Well, I ran your code in Ubuntu and compiled it well ... just the message appeared:

test.c: 18: 5: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]      gets (name);      ^ /tmp/ccQhpYWR.o: in function main': teste.c:(.text+0x45): aviso: the gets' function is dangerous and should not be used.

But it is running ... so I took a look around here this error is that this function gets already outdated; the compiler runs but gives this warning there ... I tested here instead of that gets fgets (name, 100, stdin) ... it worked fine.

    
02.11.2014 / 03:26