0

Why this program is not run please help me

#include<stdio.h> void printstr(char str[]); { int i=0; while(str[i]!=\'0') { printf("%c",str[i]); i++; } } int main() { char str="ahsan"; printstr(str); return 0; }

17th Dec 2022, 12:35 PM
Khan Ahsan
Khan Ahsan - avatar
3 Answers
+ 2
char str ; is character variable declaration. You can only store single character, not a string. To store string you need character array so declare character array or character pointer. char str[] = "ahsan"; char* str = "ahsan"; // using pointer if you know.. edit: 2 more mistake are in \'0' and semicolon after function name. correct way '\0' and remove semicolon.
17th Dec 2022, 1:30 PM
Jayakrishna 🇼🇳
+ 1
It surely ouputs an error message. Check it as first measure, so you know where to start. Also, pls edit your question with: 1. Change the tag for one with the language name 2. Change the pasted code in question description for a link to your code in Code Playground - use "+" button 3. Include the full and unmodified error message in the question description
17th Dec 2022, 1:15 PM
Emerson Prado
Emerson Prado - avatar
0
Sorry i am new student
17th Dec 2022, 1:24 PM
Khan Ahsan
Khan Ahsan - avatar