Anonymous user
Extract file extension: Difference between revisions
→{{header|C}}: Adjusted code to changed requirements
(→{{header|Go}}: Adjusted code to the changed task description) |
(→{{header|C}}: Adjusted code to changed requirements) |
||
Line 248:
=={{header|C}}==
<lang C>#include <assert.h>▼
▲#include <assert.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
/* Returns a pointer to the extension of 'string'.
*
char* file_ext(const char *string)
{
Line 267 ⟶ 264:
for (char *iter = ext + 1; *iter != '\0'; iter++) {
if (!isalnum((unsigned char)*iter))
return (char*) string + strlen(string);
}
return ext
}
int main(void)
{
const char *
{"
{"
{"
{"
{"
{"
};
int exitcode = 0;
for (
const char *ext = file_ext(testcases[i][0]);
if (strcmp(ext, testcases[i][1]) != 0) {
fprintf(stderr, "expected '%s' for '%s', got '%s'\n",
testcases[i][1], testcases[i][0], ext);
exitcode = 1;
}
}
return exitcode;
}</lang>
=={{header|C++}}==
|