Skip to content

Instantly share code, notes, and snippets.

@danielkza
Created July 26, 2014 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielkza/36adc4e0259637e6ecda to your computer and use it in GitHub Desktop.
Save danielkza/36adc4e0259637e6ecda to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
char buf[16];
while(fgets(buf, sizeof(buf), stdin) != NULL) {
char *space_pos = strchr(buf, ' ');
if(space_pos == NULL) {
printf("Linha inválida\n");
} else {
char *valor = strndup(buf, space_pos - buf);
char *naipe = strdup(space_pos + 1);
printf("Valor: %s Naipe: %s\n", valor, naipe);
free(valor);
free(naipe);
}
if(strchr(buf, '\n') == NULL) {
while(fgetc(stdin) != '\n') {
// pass
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment