i need my program to read in a file reverse it then write the file out.
i got the reverse correct but its not working.my errors are:
n.c:12: warning: passing argument 1 of 'fopen' from incompatible pointer type
n.c:21: warning: passing argument 1 of 'fopen' from incompatible pointer type
n.c:22: warning: passing argument 1 of 'fputs' from incompatible pointer type
n.c:22: error: too few arguments to function 'fputs'

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
 char string[256];
 char*filename[256];
 char*outfilen[256];
 char c;
 int len;
 FILE * infile=0;
FILE * outfile;
infile=fopen(filename,"r");
 fgets(string, sizeof string, stdin);
 len = (strlen(string) - 1);
 
 printf("Reverse string:\n");
 for(; len >= 0; len--)
        printf("%c",string[len]);

 printf("\n");
outfile=fopen(outfilen,"w");
fputs(outfile);
fclose(infile);
fclose(outfile);
}

>n.c:12: warning: passing argument 1 of 'fopen' from incompatible pointer type infile=fopen(filename,"r"); Needs to be a string. You are passing it an array of pointers, char*filename[256]; and none of them have a valid string. Where's the name of the file to be read?

>FILE * infile=0;
Just delete that in red.

>n.c:22: warning: passing argument 1 of 'fputs' from incompatible pointer type
>n.c:22: error: too few arguments to function 'fputs' fputs(outfile); The first argument must be a string; outfile is not. fpus() require a second argument which is a pointer to a FILE; outfile would fit the bill.

printf("Reverse string:\n");
 for(; len >= 0; len--)
        printf("%c",string[len]);

Using printf() there you are displaying the reverse of the string to the monitor which is the standard output. Don't you mean to write it to another file?
If you change printf() for fputc( c, outfile ) it will write a character at a time into the file that outfile points to. However, that would create a long line with not newline characters.

hi frnd
i saw the program u have declares the variable filename as string pointer array u have
to declare the string either as
char *filename;
or
char filename[256];
bye

ITS GIVING ME ERROR AS error: too few arguments to function ‘strnlen’
SUGGEST ME A SOLUTION FOR THIS PROBLEM.

int apnlength;

u_char apn_name[]="LTE";

struct sockaddr_in ggsn,sgsn;



apnlength = strnlen(apn_name);

ITS GIVING ME ERROR AS error: too few arguments to function ‘strnlen’

strnlen()
strlen()

Small but significant differences.

#include <stdio.h>
void Reverse();
int main()
{
    printf("Enter a sentence: ");
    Reverse();
    return 0;
}
void Reverse()
{
    char c;
    scanf("%c",&c);
    if( c != '\n')
    {
        Reverse();
        printf("%c",c);
    }
}

i think it will be like this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.