Ponteiros
Publicado por Enzo de Brito Ferber 15/09/2006
[ Hits: 4.878 ]
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; }
SIMULADOR DE DADOS DE RPG VAMPIRO A MÁSCARA - Corrigido
Cálculo de divisores de um número.
Nenhum coment�rio foi encontrado.
Atualizando o Passado: Linux no Lenovo G460 em 2025
aaPanel - Um Painel de Hospedagem Gratuito e Poderoso
O macete do Warsaw no Linux Mint e cia
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)
Instalação de Ubuntu em SSD (interno) como se fosse um dispositivo ext... (1)
Mikrotik não abre o webmail-segur... da Locaweb (10)