Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int neoStrlen(char test[]);
- void neoStrcpy(char test[], char test2[]);
- int neoStrcmp(char test[], char test2[]);
- int main() {
- char testString[20],testString2[20];
- printf("Entre com uma string:\n");
- gets(testString);
- printf("Entre com outra string:\n");
- gets(testString2);
- printf("Quantidade de caracteres da primeira string : %d\n",neoStrlen(testString));
- printf("Quantidade de caracteres da segunda string : %d\n",neoStrlen(testString2));
- printf("0(iguais), -1(primeira < segunda), 1(primeira > segunda) : %d\n",neoStrcmp(testString,testString2));
- neoStrcpy(testString,testString2);
- printf("Teste de copia (segunda string para perimeira) -> %s\n",testString);
- printf("Ira aparecer 0 se ambas forem iguais : %d\n",neoStrcmp(testString,testString2));
- return 0;
- }
- int neoStrlen(char test[]) {
- int i = 0,counter = 0;
- while (test[i++] != '\0')
- counter++;
- return counter;
- }
- void neoStrcpy(char test[], char test2[]) {
- int i = 0;
- while (test[i] != '\0' || test2[i] != '\0') {
- test[i] = test2[i];
- i++;
- }
- }
- int neoStrcmp(char test[], char test2[]) {
- int i = 0;
- while (test[i] != '\0') {
- if (test[i] > test2[i])
- return 1;
- else if (test[i] < test2[i])
- return -1;
- else
- i++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment