How to Write a program that prompts the user to input a string, (whitespaces allowed)
Add code to:
Step 1: allocate memory for the string
Step 2: Scanf the string from the user
Step 3: Write a function to calculate the length of the string.
int length(char name[]);Â
Solution:
/*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; }
Learn More :
Enter by User
- C Program to Enter an ODD number between 1 and 49.
- C Program to Calculation of One Number Raised to Another
- C Program to Count Vowels, Consonants and Spaces in a string
- C Program to calculate Area, Perimeter of Rectangle; Area, Circumference of Circle.
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- C Program to find result where value and power are user given
- C Program That in a Given Natural Number x Insert Figure c at Position p
- C Program To Find Prime Number And If Number Is Not Prime Then Find Factors
- C program that lets the user choose if he wants to add a item to the shopping list or print it out
- C Program to Input Number by the user between 1-100
- How to Gets User Input For Height in C Programming
- Loudness Program: Gets loudness level from user; chooses a response And prints it using logical and operative statements
- C Program Exchange User Entered Text Between 2 Modules
- C Program to accept n numbers from user & find out the maximum element out of them by using dynamic memory allocation
- C Program to accept string from user & convert all lower case letters into upper case letters & vice versa
- C Program to accept m*n matrix from user and display the elements of given matrix using function
- C Program to accept n numbers from user store these numbers into an array & calculate average of n numbers
- C program to accept n number from user,store these numbers into an array & count the no of occurrences of each number
- C Program to accept n numbers from user store these numbers into an array & reverse an array elements using function
- C Program to accept a string from user, delete all vowels from that string & display the result
- Write a c program to accept a string from user & generate following pattern (e.g, input "abcd")
- C Program to accept 5 names from user & store these names into an array. Sort these array elements in alphabetical order
- C Program to accept n numbers from user,store these numbers into an array & sort the number of an array
- C Program to accept n numbers from user, store these numbers into an array. Find out Maximum & Minimum number from an Array
Calculate
- C Programm zur Berechnung von Umfang und Flächeninhalt verschiedener geomatrischer Figuren
- Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.
- C Program to Calculate GCD using recursion
- C Program To Calculate First Numbers Using Recursion
- C Program to Calculation of One Number Raised to Another
- C Program to calculate TT and Recharge Amount
- C Program to Calculate 2 numbers with 1 operation
- Un-sortiertes Array and Sortiertes Array
- C Program Calculation of Simple Interest
- C Program to Calculation of Total and Percentage
- C Program for calculation of Gross Salary
- C Program to calculate Area, Perimeter of Rectangle; Area, Circumference of Circle.
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- C Program for statistically calculating pi using a specific scheduling policy.
- C Program Number of Judge and Score From Each Judge
- C Program to Calculate the mathematical expression for the first n numbers
- C Program to Calculate the price of movie tickets
- C Program to calculate sum of two m*n matrices & store the result in 3 matrix
- C Program to calculate the sum of elements of upper triangle of a n*n matrix using DMA
- C Program to accept n numbers from user store these numbers into an array & calculate average of n numbers
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of non-diagonal element in m*n matrix C Program
- Accept n number from user, store these number into an array and calculate the average of n number
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
Function
- How to pass one dimensional array to function in c.
- Write a c program which passes two dimension array to function.
- Write overloaded function templates for finding the roots of the linear (a * x + b = 0) and square (a * x2 + b * x + c = 0) uravneniy.Zamechanie: in function to send coefficients of the equations.
- C Program Character toupper() Example
- C Program Function Example
- Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.
- C Program To Find LCM and HCF Of Two Number Using Function - 2
- C Program To Convert Temperature In Celsius To Fahrenheit, Using Function
- C Program To Find Simple Interest
- C Function to Check Vowel
- Factorial Program In C Using Function
- C Program For Prime Number Using Function
- C Function to xorSwap and addSwap in C Programming
- C Program to concatenate two strings without using string functions
- C Function to read instructions from the file and obey them
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- C Program to Implements a dictionary's functionality.
- = (int*)malloc(sizeof(int)) ??
- Design a C function that shortens a string to 8 characters
- C Program to Implements a dictionary's functionality
- Local sounds functions in C Program
- Function Get the resource that will be gathered from the zone name
- C Program to Find the Size of File using File Handling Function
- Average function in C
Data From User
Char
Allowed
Add
- C Program To Add Digits Of Entered Number
- C Program To Add n Numbers
- C program to add first seven terms of the following series using a for loop: (1/1!) + (2/2!) + (3/3!) + .....
- C Program to Adds literal to list of literals
- C Program to Add-Subtract Series 5-10+15
- C Program to Add Series 1+3+5
- C program that lets the user choose if he wants to add a item to the shopping list or print it out
- C Program to : add/sub/multi/divi works
- Adding two polynomial functions C Program Using Structure
- Program to Add Two Polynomials Using Linked List C Program
Input
- C Program to Get User Input and Compare
- C Program Basic logging of user input/output
- C Program File Input & Output Example
- C Program To Input & Print More Than One Words In Single Line
- Take microphone input and send to headphones
- A small I/O bound program to copy N bytes from an input file to an output file.
- C Program That in a Given Natural Number x Insert Figure c at Position p
- Input reads in the array positions and range for random generation.
- C Program to Input Number by the user between 1-100
- How to Gets User Input For Height in C Programming
- DEMULTIPLEXER CO ANALOG INPUTS
- C Program to Simulation program for FCFS ( First Come First Serve )
- C Program to Input Student Details into a File For Two Subjects
- Program to Display Pie Chart Accepting User Input C Program
- Input a Number and Check if it's Palindrome or not C Program
- Input Number and Print it's Reverse C Program
- Input Number and Check if it's Armstrong C Program
- Input Number and Check if it's Even or Odd C Program
- Input Two Numbers and Print Greater Number C Program
- Input Number and Calculate Sum of it's Digits C Program