Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22298

Getting ***stack smashing detected*** while counting array length

$
0
0

I am using VS code on Ubuntu 20.04. I am learning C programming. The program is to count length of array using function. while running the program I can give input to the array but not getting the length of array.The code is :

#include<stdio.h>#include<string.h>int length(char input[]){    int count=0;    for(int i=0;input[i]!=0;i++)    {        count++;    }    return count;}int main(){    char name[10];    printf("Enter name:");    scanf("%s",&name[10]);    int count=length(name);    printf("%d",count);}

Output:

Enter name:abc*** stack smashing detected; terminatedAborted (core dumped)

What is wrong with the code?


Viewing all articles
Browse latest Browse all 22298

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>