add U0
This commit is contained in:
parent
c2b7284626
commit
c5981b2b7a
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
FILE *p = fopen ("teste.txt", "r");
|
||||
// testa se o arquivo foi aberto com sucesso
|
||||
if (p != NULL) {
|
||||
printf ("Arquivo foi aberto com sucesso.\n\n");
|
||||
fclose(p);
|
||||
} else {
|
||||
printf ("Nao foi possivel abrir o arquivo.\n\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
FILE *p = fopen ("teste.txt", "r");
|
||||
|
||||
// testa se o arquivo foi aberto com sucesso
|
||||
if (p != NULL) {
|
||||
printf ("Arquivo foi aberto com sucesso.\n\n");
|
||||
fclose(p);
|
||||
} else {
|
||||
printf ("Nao foi possivel abrir o arquivo.\n\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
FILE *p = fopen (argv[1], "r");
|
||||
int ch;
|
||||
|
||||
if (p != NULL) {
|
||||
do {
|
||||
ch = fgetc(p);
|
||||
if(ch != EOF){
|
||||
printf( "%i %c\n", ch, (char)ch);
|
||||
//printf( "%c", (char)ch);
|
||||
}
|
||||
} while (ch != EOF);
|
||||
fclose(p);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
FILE *p = fopen ("teste.txt", "r");
|
||||
char str[100+1];
|
||||
char* resp;
|
||||
int i = 0;
|
||||
|
||||
if (p != NULL) {
|
||||
do {
|
||||
resp = fgets(str, 100, p);
|
||||
if(resp != NULL){
|
||||
printf("(%d) %s", i, str);
|
||||
i++;
|
||||
}
|
||||
} while (resp != NULL);
|
||||
fclose(p);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
FILE *p = fopen ("teste.txt", "w");
|
||||
fputc('M', p);
|
||||
fclose(p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
FILE *p = fopen ("teste.txt", "w");
|
||||
fputs("Algoritmos e Estruturas de Dados II", p);
|
||||
fclose(p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
FILE *in = fopen ("teste.txt", "r"),
|
||||
*out = fopen ("copia.txt", "w");
|
||||
|
||||
while ( !feof(in) ) {
|
||||
char ch = getc(in);
|
||||
if ( !feof(in)) {
|
||||
putc(ch, out);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
FILE *p;
|
||||
|
||||
double d = 12.23;
|
||||
int i = 101;
|
||||
long l = 123023L;
|
||||
|
||||
if ((p = fopen("teste.txt", "wb")) == NULL) {
|
||||
printf ("arquivo nao pode ser aberto\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fwrite(&d, sizeof(double), 1, p);
|
||||
fwrite(&i, sizeof(int), 1, p);
|
||||
fwrite(&l, sizeof(long), 1, p);
|
||||
|
||||
fclose(p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
FILE *p;
|
||||
|
||||
double d;
|
||||
int i;
|
||||
long l;
|
||||
|
||||
if ((p = fopen("teste.txt", "rb")) == NULL) {
|
||||
printf ("arquivo nao pode ser aberto\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fread(&d, sizeof(double), 1, p);
|
||||
fread (&i, sizeof(int), 1, p);
|
||||
fread (&l, sizeof(long), 1, p);
|
||||
|
||||
printf("%f %d %ld", d, i, l);
|
||||
fclose(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct cliente {
|
||||
char nome[100];
|
||||
int codigo;
|
||||
} cliente;
|
||||
|
||||
void escrever(char*);
|
||||
void ler(char*);
|
||||
|
||||
void main(int argc, char** argv){
|
||||
escrever("teste.txt");
|
||||
ler("teste.txt");
|
||||
}
|
||||
|
||||
void escrever(char* nomeArq){
|
||||
cliente c1, c2;
|
||||
strcat(c1.nome, "Ze da Silva"); c1.codigo = 1;
|
||||
strcat(c2.nome, "Lele da Cuca"); c2.codigo = 11;
|
||||
FILE *p = fopen(nomeArq, "ab");
|
||||
fwrite(&c1, sizeof(cliente), 1, p);
|
||||
fwrite(&c2, sizeof(cliente), 1, p);
|
||||
fclose(p);
|
||||
}
|
||||
|
||||
void ler(char* nomeArq){
|
||||
cliente c1, c2;
|
||||
FILE *p = fopen(nomeArq, "rb");
|
||||
fread(&c1, sizeof(cliente), 1, p);
|
||||
fread(&c2, sizeof(cliente), 1, p);
|
||||
fclose(p);
|
||||
printf("%s -- %d\n", c1.nome, c1.codigo);
|
||||
printf("%s -- %d\n", c2.nome, c2.codigo);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
FILE *p = fopen("teste.txt", "wb+");
|
||||
|
||||
double d = 12.23; int i = 101; long l = 123023L;
|
||||
|
||||
|
||||
fwrite(&d, sizeof(double), 1, p);
|
||||
fwrite(&i, sizeof(int), 1, p);
|
||||
fwrite(&l, sizeof(long), 1, p);
|
||||
|
||||
rewind(p);
|
||||
|
||||
fread(&d, sizeof(double), 1, p);
|
||||
fread (&i, sizeof(int), 1, p);
|
||||
fread (&l, sizeof(long), 1, p);
|
||||
|
||||
printf("%f %d %ld", d, i, l);
|
||||
fclose(p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
FILE *p = fopen("teste.txt", "wb+");
|
||||
int registro, valor, i;
|
||||
|
||||
for (i = valor = 0; i < 10; i++, valor = i * 10) fwrite(&valor, sizeof(int), 1, p);
|
||||
|
||||
int numRegistro = ftell(p) / sizeof (int);
|
||||
|
||||
do {
|
||||
printf ("\nEscolha um numero entre zero e %i: ", numRegistro-1);
|
||||
scanf("%d", ®istro);
|
||||
} while (registro < 0 || registro >= numRegistro);
|
||||
|
||||
fseek(p, registro * sizeof(int), SEEK_SET);
|
||||
fread(&valor, sizeof(int), 1, p);
|
||||
fclose(p);
|
||||
printf ("\nValor: %d\n\n", valor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//=============================================================================
|
||||
void gravar_arquivo_texto(){
|
||||
|
||||
// ABRIR O ARQUIVO
|
||||
FILE *arq = fopen("arquivo.txt", "w");
|
||||
|
||||
if(arq == NULL){
|
||||
printf("Erro ao tentar abrir o arquivo!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// ESCREVER NO ARQUIVO
|
||||
fprintf(arq, "%s\t", "Algoritmos");
|
||||
fprintf(arq, "%d\t", 1);
|
||||
fprintf(arq, "%f\t", 5.3);
|
||||
fprintf(arq, "%c\t", 'X');
|
||||
|
||||
// FECHA O ARQUIVO
|
||||
fclose(arq);
|
||||
}
|
||||
//=============================================================================
|
||||
void ler_texto_texto(){
|
||||
|
||||
char texto[12], caracter;
|
||||
int inteiro;
|
||||
float real;
|
||||
|
||||
// ABRIR O ARQUIVO
|
||||
FILE *arq = fopen("arquivo.txt", "r");
|
||||
|
||||
if(arq == NULL){
|
||||
printf("Erro ao tentar abrir o arquivo!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// LE O ARQUIVO
|
||||
fscanf(arq, "%99[^\t]\t", &texto); // LER STRING
|
||||
fscanf(arq, "%d\t", &inteiro);
|
||||
fscanf(arq, "%f\t", &real);
|
||||
fscanf(arq, "%c\t", &caracter);
|
||||
|
||||
// FECHA O ARQUIVO
|
||||
fclose(arq);
|
||||
|
||||
printf("texto: %s\n", texto);
|
||||
printf("inteiro: %d\n", inteiro);
|
||||
printf("real: %f\n", real);
|
||||
printf("caracter: %c\n", caracter);
|
||||
}
|
||||
//=============================================================================
|
||||
void gravar_arquivo_binario(){
|
||||
|
||||
char texto[12] = "Algoritmos", caracter = 'X';
|
||||
int inteiro = 1;
|
||||
float real = 5.3;
|
||||
|
||||
// ABRIR O ARQUIVO
|
||||
FILE *arq = fopen("arquivo.bin", "wb");
|
||||
|
||||
if(arq == NULL){
|
||||
printf("Erro ao tentar abrir o arquivo!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// ESCREVER NO ARQUIVO
|
||||
fwrite(&texto, sizeof(char), 12, arq);
|
||||
fwrite(&inteiro, sizeof(int), 1, arq);
|
||||
fwrite(&real, sizeof(float), 1, arq);
|
||||
fwrite(&caracter,sizeof(char), 1, arq);
|
||||
|
||||
// FECHA O ARQUIVO
|
||||
fclose(arq);
|
||||
}
|
||||
//=============================================================================
|
||||
void ler_texto_binario(){
|
||||
|
||||
char texto[12], caracter;
|
||||
int inteiro;
|
||||
float real;
|
||||
|
||||
// ABRIR O ARQUIVO
|
||||
FILE *arq = fopen("arquivo.bin", "rb");
|
||||
|
||||
if(arq == NULL){
|
||||
printf("Erro ao tentar abrir o arquivo!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// LE O ARQUIVO
|
||||
fread(&texto, sizeof(char), 12, arq);
|
||||
fread(&inteiro, sizeof(int), 1, arq);
|
||||
fread(&real, sizeof(float), 1, arq);
|
||||
fread(&caracter,sizeof(char), 1, arq);
|
||||
|
||||
// FECHA O ARQUIVO
|
||||
fclose(arq);
|
||||
|
||||
printf("texto: %s\n", texto);
|
||||
printf("inteiro: %d\n", inteiro);
|
||||
printf("real: %f\n", real);
|
||||
printf("caracter: %c\n", caracter);
|
||||
}
|
||||
//=============================================================================
|
||||
|
||||
int main(){
|
||||
|
||||
gravar_arquivo_texto();
|
||||
ler_texto_texto();
|
||||
|
||||
gravar_arquivo_binario();
|
||||
ler_texto_binario();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//=============================================================================
|
||||
// EXEMPLO DE UTILIZAÇÃO DOS ARGUMENTOS PASSADOS PARA O MAIN
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
printf("%d Parametro: %s\n", i, argv[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
//=============================================================================
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
char c;
|
||||
char s[100];
|
||||
int i;
|
||||
double d;
|
||||
|
||||
printf("\nEntre com um caractere: ");
|
||||
scanf("%c", &c);
|
||||
|
||||
printf("\nEntre com uma palavra: ");
|
||||
scanf("%s", s);
|
||||
|
||||
printf("\nEntre com um inteiro e um real: ");
|
||||
scanf("%i%lf", &i, &d);
|
||||
|
||||
printf("\ninteiro(%d) real(%f) char(%c) s(%s)", i, d, c, s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void helloWorld(void){
|
||||
printf("Hello World!\n");
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef _H_TESTE
|
||||
#define _H_TESTE
|
||||
|
||||
void helloWorld(void);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "helloworld.h"
|
||||
|
||||
int main(){
|
||||
helloWorld();
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# My first makefile
|
||||
|
||||
all: printy
|
||||
|
||||
printy: main.o helloworld.o
|
||||
gcc -o printy main.o helloworld.o
|
||||
|
||||
main.o: main.c helloworld.h
|
||||
gcc -o main.o main.c -c -W -Wall -ansi -pedantic
|
||||
|
||||
helloworld.o: helloworld.c helloworld.h
|
||||
gcc -o helloworld.o helloworld.c -c -W -Wall -ansi -pedantic
|
||||
|
||||
clean:
|
||||
rm -rf *.o *~ printy
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
printf ("Ola pessoal!!!\n\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main (int argc, char** argv){
|
||||
int x = 10;
|
||||
int * y = & x;
|
||||
printf("\n%i", x);
|
||||
printf("\n%p", &x);
|
||||
printf("\n%p", y);
|
||||
printf("\n%p", &y);
|
||||
printf("\n%i", *y);
|
||||
printf("\n");
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main (int argc, char** argv){
|
||||
int x1 = 11,
|
||||
x2 = 22,
|
||||
x3 = 33;
|
||||
int *p;
|
||||
|
||||
p = &x1; //p <- o endereço de x1
|
||||
x2 = *p; //x2 <- o cont. do addr apont. por p
|
||||
*p = x3; //o cont. do addr apont. por p <- x3
|
||||
p = &x3; //p <- o endereço de x3
|
||||
*p = 0; //o cont. do addr apont. por p <- x3
|
||||
|
||||
printf("\ncont:%d %d %d %d", x1, x2, x3, *p);
|
||||
printf("\naddr:%p %p %p %p", &x1, &x2, &x3, p);
|
||||
printf("\n");
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main (int argc, char** argv){
|
||||
int *x1;
|
||||
int x2;
|
||||
int *x3;
|
||||
|
||||
x1 = (int*) malloc (sizeof(int));
|
||||
printf("\nx1(%p)(%i)(%p) x2(%i)(%p) x3(%p)(%i)(%p)", x1, *x1, &x1, x2, &x2, x3, *x3, &x3);
|
||||
|
||||
*x1 = 20;
|
||||
printf("\nx1(%p)(%i)(%p) x2(%i)(%p) x3(%p)(%i)(%p)", x1, *x1, &x1, x2, &x2, x3, *x3, &x3);
|
||||
|
||||
x2 = *x1;
|
||||
printf("\nx1(%p)(%i)(%p) x2(%i)(%p) x3(%p)(%i)(%p)", x1, *x1, &x1, x2, &x2, x3, *x3, &x3);
|
||||
|
||||
*x3 = x2 * *x1;
|
||||
printf("\nx1(%p)(%i)(%p) x2(%i)(%p) x3(%p)(%i)(%p)", x1, *x1, &x1, x2, &x2, x3, *x3, &x3);
|
||||
|
||||
x3 = &x2;
|
||||
printf("\nx1(%p)(%i)(%p) x2(%i)(%p) x3(%p)(%i)(%p)", x1, *x1, &x1, x2, &x2, x3, *x3, &x3);
|
||||
|
||||
x2 = 15;
|
||||
printf("\nx1(%p)(%i)(%p) x2(%i)(%p) x3(%p)(%i)(%p)", x1, *x1, &x1, x2, &x2, x3, *x3, &x3);
|
||||
printf("\n");
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
int main (int argc, char** argv){
|
||||
double M [3][3];
|
||||
double *p = M[0];
|
||||
|
||||
for (int i = 0; i < pow(3, 2); i++, p++){
|
||||
*p=0.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAXTAM 10
|
||||
|
||||
typedef struct Cliente {
|
||||
int codigo;
|
||||
char nome[MAXTAM];
|
||||
} Cliente;
|
||||
|
||||
|
||||
int main (int argc, char** argv){
|
||||
char* p1 = (char*) malloc (sizeof(char));
|
||||
int* p2 = (int*) malloc (sizeof(int));
|
||||
float* p3 = (float*) malloc (sizeof(float));
|
||||
Cliente* p4 = (Cliente*) malloc (sizeof(Cliente));
|
||||
int* p5 = (int*) malloc (MAXTAM * sizeof (int));
|
||||
Cliente* p6 =(Cliente*) malloc (MAXTAM * sizeof (Cliente));
|
||||
|
||||
free(p1);
|
||||
free(p2);
|
||||
free(p3);
|
||||
free(p4);
|
||||
free(p5);
|
||||
free(p6);
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#define MAXTAM 10
|
||||
|
||||
typedef struct Cliente {
|
||||
int codigo;
|
||||
char nome[MAXTAM];
|
||||
} Cliente;
|
||||
|
||||
|
||||
int main (int argc, char** argv){
|
||||
char* p1 = new char;
|
||||
int* p2 = new int;
|
||||
float* p3 = new float;
|
||||
Cliente* p4 = new Cliente;
|
||||
int* p5 = new int [MAXTAM];
|
||||
Cliente* p6 = new Cliente[MAXTAM];
|
||||
|
||||
delete p1;
|
||||
delete p2;
|
||||
delete p3;
|
||||
delete p4;
|
||||
delete [] p5;
|
||||
delete [] p6;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAXTAM 100
|
||||
|
||||
typedef struct Cliente {
|
||||
int codigo;
|
||||
char nome[MAXTAM];
|
||||
} Cliente;
|
||||
|
||||
int main (int argc, char** argv){
|
||||
Cliente registro;
|
||||
Cliente* ponteiro = (Cliente*) malloc (sizeof(Cliente));
|
||||
|
||||
registro.codigo = 1;
|
||||
strcpy(registro.nome, "AA");
|
||||
printf("\nFuncionario (%i): %s", registro.codigo, registro.nome);
|
||||
|
||||
ponteiro->codigo = 2;
|
||||
strcpy(ponteiro->nome, "BB");
|
||||
printf("\nFuncionario (%i): %s", ponteiro->codigo, ponteiro->nome);
|
||||
printf("\n");
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main (int argc, char** argv){
|
||||
double a;
|
||||
double *p, *q;
|
||||
|
||||
a = 3.14;
|
||||
printf("%f\n", a);
|
||||
|
||||
p = &a;
|
||||
*p = 2.718;
|
||||
printf("%f\n", a);
|
||||
|
||||
a = 5;
|
||||
printf("%f\n", *p);
|
||||
|
||||
p = NULL;
|
||||
p = (double*) malloc(sizeof(double));
|
||||
*p = 20;
|
||||
q = p;
|
||||
|
||||
printf("%f\n", *p);
|
||||
printf("%f\n", a);
|
||||
free(p);
|
||||
printf("%f\n", *q);
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main (int argc, char** argv){
|
||||
int a[10], *b;
|
||||
|
||||
b = a;
|
||||
b[5] = 100;
|
||||
printf("\n%d -- %d", a[5], b[5]);
|
||||
|
||||
b = (int*) malloc(10*sizeof(int));
|
||||
b[7] = 100;
|
||||
printf("\n%d -- %d", a[7], b[7]);
|
||||
printf("\n");
|
||||
|
||||
//O comando a = b gera um erro de compilação
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main (int argc, char** argv){
|
||||
int *x1;
|
||||
int x2;
|
||||
int *x3;
|
||||
|
||||
x1 = (int*) malloc(sizeof(int));
|
||||
printf("\nx1(%p)(%p)(%i) x2(%p)(%i) x3(%p)(%p)(%i)", &x1, x1, *x1, &x2, x2, &x3, x3, *x3);
|
||||
|
||||
*x1 = 20;
|
||||
printf("\nx1(%p)(%p)(%i) x2(%p)(%i) x3(%p)(%p)(%i)", &x1, x1, *x1, &x2, x2, &x3, x3, *x3);
|
||||
|
||||
x2 = *x1;
|
||||
printf("\nx1(%p)(%p)(%i) x2(%p)(%i) x3(%p)(%p)(%i)", &x1, x1, *x1, &x2, x2, &x3, x3, *x3);
|
||||
|
||||
*x3 = x2 * *x1;
|
||||
printf("\nx1(%p)(%p)(%i) x2(%p)(%i) x3(%p)(%p)(%i)", &x1, x1, *x1, &x2, x2, &x3, x3, *x3);
|
||||
|
||||
x3 = &x2;
|
||||
printf("\nx1(%p)(%p)(%i) x2(%p)(%i) x3(%p)(%p)(%i)", &x1, x1, *x1, &x2, x2, &x3, x3, *x3);
|
||||
|
||||
x2 = 15;
|
||||
printf("\nx1(%p)(%p)(%i) x2(%p)(%i) x3(%p)(%p)(%i)", &x1, x1, *x1, &x2, x2, &x3, x3, *x3);
|
||||
|
||||
x2 = 13 & 3;
|
||||
printf("\nx1(%p)(%p)(%i) x2(%p)(%i) x3(%p)(%p)(%i)", &x1, x1, *x1, &x2, x2, &x3, x3, *x3);
|
||||
|
||||
x2 = 13 | 3;
|
||||
printf("\nx1(%p)(%p)(%i) x2(%p)(%i) x3(%p)(%p)(%i)", &x1, x1, *x1, &x2, x2, &x3, x3, *x3);
|
||||
|
||||
x2 = 13 >> 1;
|
||||
printf("\nx1(%p)(%p)(%i) x2(%p)(%i) x3(%p)(%p)(%i)", &x1, x1, *x1, &x2, x2, &x3, x3, *x3);
|
||||
|
||||
x2 = 13 << 1;
|
||||
printf("\nx1(%p)(%p)(%i) x2(%p)(%i) x3(%p)(%p)(%i)", &x1, x1, *x1, &x2, x2, &x3, x3, *x3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAXTAM 10
|
||||
|
||||
typedef struct Cliente {
|
||||
int codigo;
|
||||
char nome[MAXTAM];
|
||||
} Cliente;
|
||||
|
||||
int main (int argc, char** argv){
|
||||
Cliente c;
|
||||
c.codigo = 5;
|
||||
Cliente *p = NULL;
|
||||
p = (Cliente*) malloc (sizeof(Cliente));
|
||||
p->codigo = 6;
|
||||
Cliente *p2 = &c;
|
||||
p2->codigo = 7;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct Celula {
|
||||
int elemento;
|
||||
struct Celula *prox;
|
||||
} Celula;
|
||||
|
||||
Celula *novaCelula(int elemento) {
|
||||
Celula *nova = (Celula*) malloc(sizeof(Celula));
|
||||
nova->elemento = elemento;
|
||||
nova->prox = NULL;
|
||||
return nova;
|
||||
}
|
||||
|
||||
int main (int argc, char** argv){
|
||||
Celula *tmp = novaCelula(3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct Elemento {
|
||||
int valor;
|
||||
} Elemento;
|
||||
|
||||
int main (int argc, char** argv){
|
||||
Elemento e1;
|
||||
Elemento* e2 = (Elemento*) malloc (3 * sizeof (Elemento));
|
||||
Elemento e3[3];
|
||||
Elemento** e4 = (Elemento**) malloc(3 * sizeof(Elemento*));
|
||||
e4[0] = (Elemento*) malloc(sizeof(Elemento*));
|
||||
e4[2] = (Elemento*) malloc(sizeof(Elemento*));
|
||||
|
||||
e4[0]->valor = 7;
|
||||
|
||||
printf("\n%i -- %i\n", e4[0]->valor, e4[2]->valor);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void terceiro(){
|
||||
printf("3o - inicio e fim\n");
|
||||
}
|
||||
|
||||
void segundo(){
|
||||
printf("2o - inicio\n");
|
||||
terceiro();
|
||||
printf("2o - fim\n");
|
||||
}
|
||||
|
||||
void primeiro(){
|
||||
printf("1o - inicio\n");
|
||||
segundo();
|
||||
printf("1o - fim\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
printf("main - inicio\n");
|
||||
primeiro();
|
||||
printf("main - fim\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define bool int
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
bool isUpper(char x){
|
||||
return (x >= 'A' && x <= 'Z');
|
||||
}
|
||||
|
||||
int contMaiusculo(char* s){
|
||||
int cont = 0;
|
||||
|
||||
for(int i = 0; i < strlen(s); i++){
|
||||
if(isUpper(s[i]) == true){
|
||||
cont++;
|
||||
}
|
||||
}
|
||||
return cont;
|
||||
}
|
||||
|
||||
int contMaiusculoRec(char* s, int i){
|
||||
int cont = 0;
|
||||
|
||||
if(i < strlen(s)){
|
||||
if(isUpper(s[i]) == true){
|
||||
cont++;
|
||||
}
|
||||
cont += contMaiusculoRec(s, i + 1);
|
||||
}
|
||||
return cont;
|
||||
}
|
||||
|
||||
int contMaiusculoRecursivo(char* s){
|
||||
return contMaiusculoRec(s, 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
printf("\nAlGoritmos e Estrutudas de Dados: %i", contMaiusculo("AlGoritmos e Estruturas de Dados"));
|
||||
printf("\nAlGoritmos e Estruturas de Dados: %i", contMaiusculoRecursivo("AlGoritmos e Estruturas de Dados"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int fatorial(int n){
|
||||
int resp;
|
||||
printf("\nfat (%i)", n);
|
||||
resp = (n == 1) ? 1 : n * fatorial(n-1);
|
||||
printf("\nfat n(%i): %i", n, resp);
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int n = 5;
|
||||
printf("\nFATORIAL RECURSIVO(%i): %i", n, fatorial(n));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int fibonacci(int n){
|
||||
int resp;
|
||||
printf("\nfib (%i)", n);
|
||||
resp = (n == 0 || n == 1) ? 1 : fibonacci(n-1) + fibonacci(n-2);
|
||||
printf("\nfib n(%i): %i", n, resp);
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int n = 5;
|
||||
printf("\nFIBONACCI RECURSIVO(%i): %i", n, fibonacci(n));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int multiplicacaoRec(int a, int b, int i){
|
||||
int resp = 0;
|
||||
|
||||
if(i < b){
|
||||
resp = a + multiplicacaoRec(a, b, i+1);
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
int multiplicacao(int a, int b){
|
||||
return multiplicacaoRec(a, b, 0);
|
||||
}
|
||||
|
||||
int multiplicacaoIt(int a, int b){
|
||||
int resp = 0;
|
||||
for(int i = 0; i < b; i++){
|
||||
resp = a + resp;
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int mult = multiplicacaoIt(4, 3);
|
||||
printf("\nRESPOSTA IT: %i", mult);
|
||||
|
||||
mult = multiplicacao(4, 3);
|
||||
printf("\nRESPOSTA REC: %i", mult);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void printRecursivo(int i){
|
||||
printf("\nvalor de i: %i", i);
|
||||
if(i > 0){
|
||||
printRecursivo(i-1);
|
||||
}
|
||||
printf("\nvalor de i: %i", i);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int n = 3;
|
||||
printRecursivo(n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAXTAM 100
|
||||
|
||||
struct Funcionario {
|
||||
int matricula;
|
||||
char nome[MAXTAM];
|
||||
};
|
||||
|
||||
void main (){
|
||||
struct Funcionario f;
|
||||
|
||||
printf("\nEntre com a matricula: ");
|
||||
scanf("%d", &f.matricula);
|
||||
|
||||
printf("\nEntre com o nome: ");
|
||||
scanf("%s", f.nome);
|
||||
|
||||
printf("\nMatricula: %d", f.matricula);
|
||||
printf("\nNome: %s", f.nome);
|
||||
printf("\n\n");
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#define MAXTAM 100
|
||||
|
||||
struct Funcionario {
|
||||
int matricula;
|
||||
char nome[MAXTAM];
|
||||
};
|
||||
|
||||
typedef struct Funcionario Funcionario;
|
||||
|
||||
void main (){
|
||||
Funcionario f;
|
||||
|
||||
printf("\nEntre com a matricula: ");
|
||||
scanf("%d", &f.matricula);
|
||||
|
||||
printf("\nEntre com o nome: ");
|
||||
scanf("%s", f.nome);
|
||||
|
||||
printf("\nMatricula: %d", f.matricula);
|
||||
printf("\nNome: %s", f.nome);
|
||||
printf("\n\n");
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#define MAXTAM 100
|
||||
|
||||
typedef struct Funcionario {
|
||||
int matricula;
|
||||
char nome[MAXTAM];
|
||||
} Funcionario;
|
||||
|
||||
void main (){
|
||||
Funcionario f;
|
||||
|
||||
printf("\nEntre com a matricula: ");
|
||||
scanf("%d", &f.matricula);
|
||||
|
||||
printf("\nEntre com o nome: ");
|
||||
scanf("%s", f.nome);
|
||||
|
||||
printf("\nMatricula: %d", f.matricula);
|
||||
printf("\nNome: %s", f.nome);
|
||||
printf("\n\n");
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#define MAXTAM 100
|
||||
|
||||
struct Funcionario {
|
||||
int matricula;
|
||||
char nome[MAXTAM];
|
||||
};
|
||||
|
||||
typedef struct Funcionario Funcionario;
|
||||
|
||||
void main (){
|
||||
Funcionario vet[MAXTAM];
|
||||
int n = 3;
|
||||
|
||||
for(int i = 0; i < n; i++){
|
||||
printf("\nEntre com a matricula do funcionario %d: ", (i+1));
|
||||
scanf("%d", &vet[i].matricula);
|
||||
|
||||
printf("\nEntre com o nome do funcionario %d: ", (i+1));
|
||||
scanf("%s", vet[i].nome);
|
||||
}
|
||||
|
||||
for(int i = 0; i < n; i++){
|
||||
printf("\nMatricula do funcionario %d: %d", (i+1), vet[i].matricula);
|
||||
printf("\nNome do funcionario %d: %s\n", (i+1), vet[i].nome);
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int a = sizeof(char),
|
||||
b = sizeof(int),
|
||||
c = sizeof(double),
|
||||
d = sizeof(float);
|
||||
|
||||
printf ("Tamanho do char: %i\n", a);
|
||||
printf ("Tamanho do int: %i\n", b);
|
||||
printf ("Tamanho do double: %i\n", c);
|
||||
printf ("Tamanho do float: %i\n", d);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
char s1[80], s2[80];
|
||||
|
||||
strcpy(s1, "Algoritmos");
|
||||
strcpy(s2, " e Estruturas de Dados II");
|
||||
|
||||
printf("\nTamanho s1(%i)", (int)strlen(s1));
|
||||
printf("\nTamanho s2(%i)", (int)strlen(s2));
|
||||
|
||||
if(!strcmp(s1, s2)) printf("\nIguais!!!");
|
||||
else printf("\nDiferentes!!!");
|
||||
|
||||
strcat(s1, s2);
|
||||
printf("\nNova s1 (%s)", s1);
|
||||
|
||||
strcpy(s2, s1);
|
||||
printf("\nNova s2 (%s)", s2);
|
||||
|
||||
if(!strcmp(s1, s2)) printf("\nIguais!!!");
|
||||
else printf("\nDiferentes!!!");
|
||||
|
||||
s1[10] = s2[10] = '\0'; s1[11] = 'a'; s2[11] = 'b';
|
||||
printf("\nNova s1 (%s)", s1);
|
||||
printf("\nNova s2 (%s)", s2);
|
||||
|
||||
if(!strcmp(s1, s2)) printf("\nIguais!!!");
|
||||
else printf("\nDiferentes!!!");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ int main(int argc, char **argv) {
|
|||
crescente(array, n);
|
||||
print_array(array, n);
|
||||
comeco = clock();
|
||||
bolha(array, n);
|
||||
bubbleSort(array, n);
|
||||
fim = clock();
|
||||
total = (clock() - comeco) / (double)CLOCKS_PER_SEC / 1000.0;
|
||||
print_array(array, n);
|
||||
|
|
@ -36,7 +36,7 @@ int main(int argc, char **argv) {
|
|||
decrescente(array, n);
|
||||
print_array(array, n);
|
||||
comeco = clock();
|
||||
bolha(array, n);
|
||||
bubbleSort(array, n);
|
||||
fim = clock();
|
||||
total = (clock() - comeco) / (double)CLOCKS_PER_SEC / 1000.0;
|
||||
print_array(array, n);
|
||||
|
|
@ -46,7 +46,7 @@ int main(int argc, char **argv) {
|
|||
aleatorio(array, n);
|
||||
print_array(array, n);
|
||||
comeco = clock();
|
||||
bolha(array, n);
|
||||
bubbleSort(array, n);
|
||||
fim = clock();
|
||||
total = (clock() - comeco) / (double)CLOCKS_PER_SEC / 1000.0;
|
||||
print_array(array, n);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#ifndef BOLHA_H
|
||||
#define BOLHA_H
|
||||
#ifndef BUBBLESORT_H
|
||||
#define BUBBLESORT_H
|
||||
//=============================================================================
|
||||
#include "ordenacao.h"
|
||||
#include "sort.h"
|
||||
//=============================================================================
|
||||
void bolha(int *array, int n){
|
||||
void bubbleSort(int *array, int n){
|
||||
int i, j;
|
||||
for (i = (n - 1); i > 0; i--) {
|
||||
for (j = 0; j < i; j++) {
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef INSERTSORT_H
|
||||
#define INSERTSORT_H
|
||||
//=============================================================================
|
||||
#include "sort.h"
|
||||
//=============================================================================
|
||||
void insertSort(int *array, int n){
|
||||
int i, j, tmp;
|
||||
for (int i = 1; i < n; i++) {
|
||||
tmp = array[i];
|
||||
int j = i - 1;
|
||||
|
||||
while ((j >= 0) && (array[j] > tmp)) {
|
||||
array[j + 1] = array[j];
|
||||
j--;
|
||||
}
|
||||
array[j+1] = tmp;
|
||||
}
|
||||
}
|
||||
//=============================================================================
|
||||
#endif
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef SELECTSORT_H
|
||||
#define SELECTSORT_H
|
||||
//=============================================================================
|
||||
#include "sort.h"
|
||||
//=============================================================================
|
||||
void selectSort(int *array, int n){
|
||||
int i, j, indice;
|
||||
for (i = 0; i < (n - 1); i++) {
|
||||
indice = i;
|
||||
for (j = (i + 1); j < n; j++){
|
||||
if (array[indice] > array[j]){
|
||||
indice = j;
|
||||
}
|
||||
}
|
||||
swap(&array[indice], &array[i]);
|
||||
}
|
||||
}
|
||||
//=============================================================================
|
||||
#endif
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef ORDENACAO_H
|
||||
#define ORDENACAO_H
|
||||
#ifndef SORT_H
|
||||
#define SORT_H
|
||||
//=============================================================================
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
|
@ -40,7 +40,7 @@ void aleatorio(int *array, int n) {
|
|||
}
|
||||
}
|
||||
//=============================================================================
|
||||
// PROCEDIMENTO PARA EXIBIR OS DADOS PRESENTES NO arranjo
|
||||
// PROCEDIMENTO PARA EXIBIR OS DADOS PRESENTES NO ARRANJO
|
||||
void print_array(int *array, int n) {
|
||||
int i;
|
||||
printf("[ ");
|
||||
Loading…
Reference in New Issue