Mudanças entre as edições de "Guia Básico de C"
Ir para navegação
Ir para pesquisar
Linha 14: | Linha 14: | ||
| <tt>fputs</tt> || Equivalente ao <tt>fprintf</tt>, adicionando um ENTER ao final da linha. || <syntaxhighlight lang=c>fputs("O usuário %s tem %d anos\n.", usuario, idade, arquivo1);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c970.html#c976 fputs] | | <tt>fputs</tt> || Equivalente ao <tt>fprintf</tt>, adicionando um ENTER ao final da linha. || <syntaxhighlight lang=c>fputs("O usuário %s tem %d anos\n.", usuario, idade, arquivo1);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c970.html#c976 fputs] | ||
|- | |- | ||
− | | rowspan="3" | Manipulação de Arquivos || <tt>fopen</tt> || Abre um arquivo. || < | + | | rowspan="3" | Manipulação de Arquivos || <tt>fopen</tt> || Abre um arquivo. || <syntaxhighlight lang=c>arquivo = fopen('/diretorio/arquivo.txt', 'r');</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c950.html#c951 fopen] |
|- | |- | ||
− | | fclose | + | | <tt>fclose</tt> || Fecha uma arquivo. || <syntaxhighlight lang=c>fclose(aqruivo);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c950.html#c953 fclose] |
|- | |- | ||
− | | feof | + | | <tt>feof</tt> || Indica o final do arquivo. || <syntaxhighlight lang=c>if(feof(arquivo)) printf("Final do arquivo!");</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c960.html#c963 feof] |
|- | |- | ||
| rowspan="4" | <tt>[http://opengroup.org/onlinepubs/007908775/xsh/string.h.html string.h]</tt> || Informação || <tt>strlen</tt> || Informa o tamanho da ''string''. || <syntaxhighlight lang=c>tamanho = strlen(frase);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c520.html#c524.html strlen] | | rowspan="4" | <tt>[http://opengroup.org/onlinepubs/007908775/xsh/string.h.html string.h]</tt> || Informação || <tt>strlen</tt> || Informa o tamanho da ''string''. || <syntaxhighlight lang=c>tamanho = strlen(frase);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c520.html#c524.html strlen] |
Edição das 12h54min de 26 de novembro de 2009
Bilioteca | Funcionalidade | Função | O que faz? | Exemplo | Referência do curso de C |
stdio.h | Entrada de Dados | scanf | Lê informação da entrada de dados padrão. | scanf("%s", frase);
|
scanf |
fscanf | Lê informação de um arquivo. | fscanf(arquivo, frase);
|
fscanf | ||
fgets | Equivalente a fscanf, porém especifica a quantidade de bytes a serem lidos. | fgets(frase, sizeof(frase), arquivo);
|
fgets | ||
Saída de Dados | printf | Imprime uma informação na tela. | printf("O usuário %s tem %d anos\n.", usuario, idade);
|
printf | |
fprintf | Imprime uma informação em um arquivo. | fprintf(arquivo1, "O usuário %s tem %d anos\n.", usuario, idade);
|
fprintf | ||
fputs | Equivalente ao fprintf, adicionando um ENTER ao final da linha. | fputs("O usuário %s tem %d anos\n.", usuario, idade, arquivo1);
|
fputs | ||
Manipulação de Arquivos | fopen | Abre um arquivo. | arquivo = fopen('/diretorio/arquivo.txt', 'r');
|
fopen | |
fclose | Fecha uma arquivo. | fclose(aqruivo);
|
fclose | ||
feof | Indica o final do arquivo. | if(feof(arquivo)) printf("Final do arquivo!");
|
feof | ||
string.h | Informação | strlen | Informa o tamanho da string. | tamanho = strlen(frase);
|
strlen |
Busca | strchr e strchr | Localizam a primeira e última ocorrência, respectivamente, de um caractere na string. | primeiro = strchr(frase, 'a');
ultimo = srtrchr(frase, 'a');
|
strlen | |
Comparação | strcmp | Compara duas strings. | iguais = strcmp(frase, palavra);
|
strcmp | |
Cópia | strcpy | Copia o conteúdo de uma string para outra. | strcpy(destino, origem);
|
strcpy |