What does the = '-';
or = '/'
mean in strchr
(I know it does locate work and strrchr
of last occurrence)?
This code does create two files.
#include <stdio.h>
#include <string.h>
int main()
{
FILE *fpA = fopen("output_A.txt", "w");
FILE *fpB = fopen("output_B.txt", "w");
char *strA = ",-/";
char temp[100];
char str[5][60] = { { "summer is coming!" },
{ "vacation will let you chill out" },
{ "and, have a nice time" },
{ "and, stay fit" },
{ "and, wish you the best" }, };
fprintf(fpA, "%s\n", str[0]);
fprintf(fpB, "%s\n", str[1]);
fclose(fpA);
fclose(fpB);
fpA = fopen("output_A.txt", "r");
fpB = fopen("output_B.txt", "w");
*(strchr(str[2], ' ')) = '-';
*(strrchr(str[2], ' ') + 1) = '/';
strtok(str[2], strA);
strcpy(temp, strtok(NULL, strA));
str[1][8] = '\n';
str[1][9] = '\0';
strncat(temp, str[1], strlen(str[1]));
if (strcmp(str[3], str[4]))
strcat(temp, str[3]);
else
strcat(temp, str[4]);
fprintf(fpA, "%s", temp);
fprintf(fpB, "%s", temp);
fclose(fpA);
fclose(fpB);
return 0;
}