Q:

Reversing a string in a fuction and print it in main

I have to make a programm that it reads a string and a char and prints how many times the char exists in the string! then it has to call a function to reverse the string and return it to the main! HERE IS THE CODE IV DONE! there is always this error : [Error] invalid conversion from 'char' to 'char*' [-fpermissive]
#include <stdio.h>
#include <string.h>
char rev(char a[80]);

main()
{
   char a[80],b,*c;
   int l,sum,i,v,pos; 
   puts("give a string and a character");
   gets(a);
   gets(&b);
   sum=0;
   i=0;
   while(a[i]!='\0')
   { 
                    if(a[i]==b) sum=sum+1;
   i=i+1;
   pos=pos+1;
   }
   printf("the char %c exists %d times in the string",b,sum);
   c=rev(a);
   printf("the original string is: \n");
   puts(a);
   printf("the reversed string is:\n");
   puts(c);
}

char rev(char a[80])
{
    char w[80],*ptr;
    int k,i,sum;
    i=0;
    k=0;
    for(i=80;i=0;i--)
    {
    w[k]=a[i];
    k=k+1;
    }
    i=0;
    for(i=0;i=80;i++)
    {
        *ptr=w[i];
        ptr++;
    }
    return *ptr;
}

A:

#include <stdio.h>
#include <stdlib.h> 
#include<string.h>       
char* rev(char[] );
main()
{
    char a[80],b,*c;
    int l,sum,i,v,pos=0;
    puts("give a string and a character");
    scanf("%s",a);
    scanf(" %c",&b);
    sum=0;
    i=0;
    while(a[i]!='\0')
    {
            if(a[i]==b)
                     sum=sum+1;
            i=i+1;
            pos=pos+1;
    }
    printf("the char %c exists %d times in the string\n",b,sum);
    c=rev(a);
    printf("the original string is: \n");
    puts(a);
    printf("the reversed string is:\n");
    puts(c);
}
char *rev(char a[80])
{
    char w[80],*ptr;
    int i,sum;
    sum=strlen(a);
    ptr=malloc(sum);
    for(i=sum-1;i>=0;i--)
    {
            *ptr++=a[i];
    }
    return ptr-sum;
}

Try this one.

