Ponteiros
Publicado por Enzo de Brito Ferber 15/09/2006
[ Hits: 4.874 ]
Homepage: http://www.maximasonorizacao.com.br
Operações com strings com alto uso de ponteiros. De quebrar uma função tipo a strncmp. :-) Altamente recomendado para quem está aprendendo ponteiros.
/* * Programa: Operações com strings * Arquivo: strings.c * Autor: Enzo Ferber 'Slackware_10' */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> int check(char *str, char *part){ int i; char *aux; while(*str){ aux = str; *str++; if(!(cmp(aux, part,strlen(part)))){ i=1; break; }else i=0; } return i; } int cmp(char *str1, char *str2, int len){ int i = len; int res; for(i=0;i<len;i++){ if(*(str1+i) == *(str2+i)) continue; else return 1; } return 0; } char *makeLower(char *str){ int i; for(i=0;i<strlen(str);i++) str[i] = tolower(str[i]); return str; } int main(void){ char *str1; char *str2; char op; str1 = (char *)malloc(50*sizeof(char)); str2 = (char *)malloc(50*sizeof(char)); if(!str1 || !str2){ printf("- Erro ao alocar memoria\n"); exit(1); } printf("String1: "); __fpurge(stdin); scanf("%[^\n]", str1); printf("String2: "); __fpurge(stdin); scanf("%[^\n]", str2); __fpurge(stdin); printf("Diferenciar Maiusculas/Minusculas [s/n]: "); scanf("%c", &op); switch(op){ case 'n': str1 = makeLower(str1); str2 = makeLower(str2); break; case 's': break; } switch(check(str1, str2)){ case 1: printf("String1 contem String2\n"); break; case 0: printf("String1 nao contem String2\n"); break; } free(str1); free(str2); return 0; }
Fazendo o somatório de 1 até N
Programa que Exibe centro da tela
Nenhum coment�rio foi encontrado.
Aprenda a Gerenciar Permissões de Arquivos no Linux
Como transformar um áudio em vídeo com efeito de forma de onda (wave form)
Como aprovar Pull Requests em seu repositório Github via linha de comando
Visualizar arquivos em formato markdown (ex.: README.md) pelo terminal
Dando - teoricamente - um gás no Gnome-Shell do Arch Linux
Como instalar o Google Cloud CLI no Ubuntu/Debian
Mantenha seu Sistema Leve e Rápido com a Limpeza do APT!
Procurando vídeos de YouTube pelo terminal e assistindo via mpv (2025)
Alguém já usou o framework Avalonia para desenvolver interfaces de usu... (4)
Ajuda Pra Melhoria do NFTABLES. (8)
Sinto uma leve lentidão ao arrastar, miniminizar e restauras as janela... (2)
Pastas da raiz foram para a área de trabalho [RESOLVIDO] (7)