Mudanças entre as edições de "Guia Básico de C"
Ir para navegação
Ir para pesquisar
<graphviz>
(38 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
Linha 1: | Linha 1: | ||
− | + | <center><graphviz> | |
− | + | 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></center> | ||
− | * | + | =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/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= |
+ | * Inteiro | ||
+ | * Real | ||
+ | * Caractere | ||
+ | ** [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c520.html ''String''] | ||
+ | * [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/cb10.html Estrutura de dados] | ||
− | ===<tt>scanf</tt> | + | =Funções= |
− | + | {| border="1" | |
− | + | | Bilioteca || Funcionalidade || Função || O que faz? || Exemplo || Referência ao curso de C | |
− | <syntaxhighlight lang=c> | + | |- |
− | 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] |
− | </syntaxhighlight> | + | |- |
− | + | | <tt>fscanf</tt> || Lê informação de um arquivo. || <syntaxhighlight lang=c>fscanf(arquivo, frase);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c980.html#c982 fscanf] | |
− | + | |- | |
− | = | + | | <tt>fgets</tt> || Equivalente a <tt>fscanf</tt>, porém especifica a quantidade de bytes a serem lidos. || <syntaxhighlight lang=c>fgets(frase, sizeof(frase), arquivo);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c970.html#c975 fgets] |
− | + | |- | |
− | + | | rowspan="3" | Saída de Dados || <tt>printf</tt> || Imprime uma informação na tela. || <syntaxhighlight lang=c>printf("O usuário %s tem %d anos\n.", usuario, idade);</syntaxhighlight> || [http://www.ead.cpdee.ufmg.br/cursos/C/aulas/c940.html#c941 printf] | |
− | + | |- | |
− | + | | <tt>fprintf</tt> || Imprime uma informação em um arquivo. || <syntaxhighlight lang=c>fprintf(arquivo1, "O usuário %s tem %d anos\n.", usuario, idade);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c980.html#c981 fprintf] | |
− | <syntaxhighlight lang=c> | + | |- |
− | printf("O usuário %s tem %d anos\n.", usuario, idade); | + | | <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] |
− | </syntaxhighlight> | + | |- |
− | + | | 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(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] | |
− | <syntaxhighlight lang=c> | + | |- |
− | fprintf(arquivo1, "O usuário %s tem %d anos\n.", usuario, idade); | + | | 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] |
− | </syntaxhighlight> | + | |- |
− | + | | 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> | |
− | + | |- | |
− | + | | 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] | |
− | + | |- | |
− | <syntaxhighlight lang=c> | + | | Cópia || <tt>strcpy</tt> || Copia o conteúdo de uma ''string'' para outra. || <syntaxhighlight lang=c>strcpy(destino, origem);</syntaxhighlight> || [http://mico.ead.cpdee.ufmg.br/cursos/C/aulas/c520.html#c522.html strcpy] |
− | fputs("O usuário %s tem %d anos\n.", usuario, idade, arquivo1); | + | |} |
− | </syntaxhighlight> | ||
− |
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 |