Joel
Joel

Reputation: 55

(C) between and in functions - pointer

I am writing a code and i'm getting a problem when i'm initializing a int that will be the length of a char pointer ( that's redirected to a string ). Can someone tell me what did i do wrong? I'm getting a error at "int length1".
thx for helpers.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void func(char* p, int n)
{
    int length1;
    int length;
    int total;

}



int main(void){

    char str[100];
    int n;
    char* p;
    printf("Enter the N: \n");
    scanf("%d", &n);
    printf("\nEnter the string: \n");
    scanf("%s", &str);
    p = str;
    func(p, n);
    printf("%s", *p);
    system("PAUSE");
    return (0);
}

Upvotes: 0

Views: 37

Answers (1)

Karthikeyan.R.S
Karthikeyan.R.S

Reputation: 4041

change this line.

scanf("%s", &str);

into

scanf("%s",str);

then while printing,

printf("%s\n",*p);

into

printf("%s\n",p);

And in your code there is no use in calling of that function. You are not doing anything.

Upvotes: 3

Related Questions