Mudanças entre as edições de "Guia Básico de C"
Ir para navegação
Ir para pesquisar
<graphviz>
(12 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
Linha 1: | Linha 1: | ||
− | <graphviz> | + | <center><graphviz> |
digraph Programa | digraph Programa | ||
{ | { | ||
Linha 13: | Linha 13: | ||
Saída -> Entrada | Saída -> Entrada | ||
} | } | ||
− | </graphviz> | + | </graphviz></center> |
=Conceitos Importantes= | =Conceitos Importantes= | ||
− | * | + | * [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c320.html Variáveis] e [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c340.html constantes] |
− | * [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/ | + | ** [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c760.html Escopo das variáveis] |
− | * | + | * [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c370.html Expressão] |
− | * | + | * Função: |
− | + | ** [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c230.html O básico] | |
− | * | + | ** [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c770.html Passagem de parâmetro por valor e por referência] |
+ | * Fluxo do programa e [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c400.html estruturas de repetição e de decisão] | ||
=Tipos= | =Tipos= | ||
Linha 27: | Linha 28: | ||
* Real | * Real | ||
* Caractere | * Caractere | ||
− | ** ''String'' | + | ** [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c520.html ''String''] |
− | * Estrutura de dados | + | * [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/cb10.html Estrutura de dados] |
=Funções= | =Funções= | ||
{| border="1" | {| border="1" | ||
− | | Bilioteca || Funcionalidade || Função || O que faz? || Exemplo || Referência | + | | Bilioteca || Funcionalidade || Função || O que faz? || Exemplo || Referência ao curso de C |
|- | |- | ||
| rowspan="9" | <tt>[http://opengroup.org/onlinepubs/007908775/xsh/stdio.h.html stdio.h]</tt> || rowspan="3" | Entrada de Dados || <tt>scanf</tt> || Lê informação da entrada de dados padrão. || <syntaxhighlight lang=c>scanf("%s", frase);</syntaxhighlight> || [http://www.ead.cpdee.ufmg.br/cursos/C/aulas/c940.html#c942 scanf] | | rowspan="9" | <tt>[http://opengroup.org/onlinepubs/007908775/xsh/stdio.h.html stdio.h]</tt> || rowspan="3" | Entrada de Dados || <tt>scanf</tt> || Lê informação da entrada de dados padrão. || <syntaxhighlight lang=c>scanf("%s", frase);</syntaxhighlight> || [http://www.ead.cpdee.ufmg.br/cursos/C/aulas/c940.html#c942 scanf] | ||
Linha 48: | Linha 49: | ||
| 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] | | 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] | ||
|- | |- | ||
− | | <tt>fclose</tt> || Fecha uma arquivo. || <syntaxhighlight lang=c>fclose( | + | | <tt>fclose</tt> || Fecha uma arquivo. || <syntaxhighlight lang=c>fclose(arquivo);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c950.html#c953 fclose] |
|- | |- | ||
| <tt>feof</tt> || Indica o final do arquivo. || <syntaxhighlight lang=c>fim = feof(arquivo);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c960.html#c963 feof] | | <tt>feof</tt> || Indica o final do arquivo. || <syntaxhighlight lang=c>fim = feof(arquivo);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c960.html#c963 feof] | ||
Linha 55: | Linha 56: | ||
|- | |- | ||
| Busca || <tt>strchr</tt> e <tt>strchr</tt> || Localizam a primeira e última ocorrência, respectivamente, de um caractere na ''string''. || <syntaxhighlight lang=c>primeiro = strchr(frase, 'a'); | | Busca || <tt>strchr</tt> e <tt>strchr</tt> || Localizam a primeira e última ocorrência, respectivamente, de um caractere na ''string''. || <syntaxhighlight lang=c>primeiro = strchr(frase, 'a'); | ||
− | ultimo = srtrchr(frase, 'a');</syntaxhighlight> | + | ultimo = srtrchr(frase, 'a');</syntaxhighlight> |
|- | |- | ||
| Comparação || <tt>strcmp</tt> || Compara duas ''strings''. || <syntaxhighlight lang=c>iguais = strcmp(frase, palavra);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c520.html#c525.html strcmp] | | Comparação || <tt>strcmp</tt> || Compara duas ''strings''. || <syntaxhighlight lang=c>iguais = strcmp(frase, palavra);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c520.html#c525.html strcmp] |
Edição atual tal como às 15h59min de 1 de dezembro de 2009
digraph Programa { splines=true
Início [shape=circle] Entrada [shape=invtrapezium] Processamento [shape=Mrecord] Saída [shape=trapezium] Fim [shape=circle]
Início -> Entrada -> Processamento -> Saída -> Fim Saída -> Entrada }
</graphviz>Conceitos Importantes
- Variáveis e constantes
- Expressão
- Função:
- Fluxo do programa e estruturas de repetição e de decisão
Tipos
- Inteiro
- Real
- Caractere
- Estrutura de dados
Funções
Bilioteca | Funcionalidade | Função | O que faz? | Exemplo | Referência ao 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(arquivo);
|
fclose | ||
feof | Indica o final do arquivo. | fim = feof(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');
| ||
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 |