Message from C, C++ discussions

December 2019

— #include<stdio.h>
int main()
{
int i = 0;
FILE *fp = fopen("output.txt","w");

// Return if could not open file
if (fp == NULL)
return 0;

char string[] = "good bye", received_string[20];

for (i = 0; string[i]!='\0'; i++)

// Input string into the file
// single character at a time
fputc(string[i], fp);

fclose(fp);
fp = fopen("output.txt","r");

// Reading the string from file
fgets(received_string,20,fp);

printf("%s", strrev(received_string));

fclose(fp);
return 0;
}

Message permanent page

— 

Prog.c:26:9: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]

— Why not

— Https://www.geeksforgeeks.org/strrev-function-in-c/

— Strrev returns int not char* that is why it is showing you warning.

— Another one bites the dust...!
Banned Life.
Reason:
spambot?

— Returns: This function returns the string after reversing the given string.

— Ah, i see atom_t

— atom_t Look at his char array init...

— It reverse the string but not return the reversed string. It reverse the string in place. Meaning the reversed string is in the original variable passed.

Just change you code to this.
Strrev(recieved_string);
Printf("%s", recieved_string);

You can check for failure from the strrev return

Message permanent page

— Returns code of operation ?

— I dont know what it returns. But the reversed string is returned by the passed argument not by the returned value.

Message permanent page