-1
#include<stdio.h>
#include<conio.h>
#include<string.h>

void printlength(char a);

void printlength(char a)
{
    int len = strlen(a);
    printf("The Length of the String %s is %d ", a, len);
    getch();
}

void main()
{
    char a[25];
    clrscr();
    printf("Enter the name");
    scanf("%s", &a);
    printlength(a);
}

I just started learning c and stuck in these error. I am getting both the error

type mismatch in parameter error in c and type mismatch in parameter redeclaration

WedaPashi
  • 3,561
  • 26
  • 42

2 Answers2

2

I can see one problem straight away:

printf("The Length of the String %s is %d ",a,len);

%s is used with strings, and you are passing a char.

And, I can see that

printlength(a);

And a is a char array here, so, you need to change to

void printlength(char *a)

Additinally, you must get rid of & with a in your scanf(), and to avoid buffer overflows, use

scanf("%24s",a);

A textbook in C programming very a good to start off, and also take a look at the warnings your compiler is providing you with, those are meant for something rather than avoiding.

WedaPashi
  • 3,561
  • 26
  • 42
0

For starters according to the C Standard the function main without parameters shall be declared like

int main( void )

Format specifier %s expects an argument of the type char *. So the statement with the call of scanf should be written at least like

scanf("%s", a);
           ^^^

though it is more safe to write

scanf("%24s", a);

It is supposed that the function printlength deals with strings. So taking also in account that the pointed data is not changed in the function its parameter shall be declared like

void printlength( const char *a );
                  ^^^^^^^^^^^^^

The return type of the standard function strlen is size_t. So the variable len should be declared as having the type size_t.

So within the function there should be

size_t len = strlen(a);
printf("The Length of the String %s is %zu\n", a, len);

It is better to move the call of the non-standard function getch in main.

int main( void )
{
    //...

    getch();
}
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335