Over a million developers have joined DZone.

"Unget String" Function

As a complement to ungetc(), this C function pushes a string back onto an input stream, character by character.  It returns the number of characters pushed, or -1 if an error occurred.

void ungets(char* str, FILE* stream) {
 if (!str || !file) return -1;
 size_t len = strlen(str);
 for (int i=len-1; i>=0; i--) if (ungetc(str[i], stream) == EOF) return -1;
 return len;

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}