c - Print out a selected number of a string problem -


the exercise says "make function 2 parameters string (s) , integer(n). function return first n characters. that's did, i'm getting compiler error "[warning] passing arg 1 of `symbolse' makes pointer integer without cast". i've tried changes, override error don't result want or program crashes.

 #include<stdio.h>  #include<stdlib.h>   void symbolse(char s[50],int n){     int i;     for(i=0;i<n;i++)     printf("%c ",s[i]);    }  main(){    int m;    char a[50];    printf("give integer: ");    scanf("%d",&m);    printf("give string: ");    a[50]=getchar();    symbolse(a[50],m);     system("pause");    } 

ex. user gives m=3 , a[50]=house . program should print hou .

one problem a[50]=getchar(). reads 1 character 50-th position in buffer (which way out of a's bounds). trying using scanf instead.

symbolse(a[50],m) wrong. i'll let figure out problem is.

one further hint print out values of input variables ensure you've read them correctly.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -