How to write a C Program scanf & gets Example in C Programming Language ?
Solution For C Program :
Learn To Write A Program. Learn Programming Online. Find Programming Solutions.
/*Write a program that prompts the user to input a string, (whitespaces allowed) Add code to: step1: allocate memory for the string step2: Scanf the string from the user step3: Write a function to calculate the length of the string. int length(char name[]);Â */ #include<stdio.h> #define SIZE 41 int main() { //Define student name char name[SIZE]; printf("Please enter your name:"); scanf("%[^\n]",name); printf("The length of the name is %d",length(name)); getch(); } int length(char name[]) { int i,result=0; for(i=0;name[i]!='\0';i++) result++; return result; }