Created
May 6, 2011 17:27
-
-
Save carlosbrando/959381 to your computer and use it in GitHub Desktop.
Uma versão muito simples da função gets() da biblioteca padrão.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/* Uma versão muito simples da função gets() | |
* da biblioteca padrão. */ | |
char *xgets(char *s) | |
{ | |
char ch, *p; | |
int t; | |
p = s; /* gets() devolve um ponteiro para s */ | |
for (t = 0; t < 80; ++t) { | |
ch = getchar(); | |
switch(ch) { | |
case '\n': | |
s[t] = '\0'; /* termina a string */ | |
return p; | |
case '\b': | |
if (t > 0) t--; | |
break; | |
default: | |
s[t] = ch; | |
} | |
} | |
s[80] = '\0'; | |
return p; | |
} | |
main(void) | |
{ | |
char message[80]; | |
xgets(message); | |
printf("%s\n", message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment