Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've only started using C and have a question about using characters like someones name in c instead of integers, here i have a simple grading program below, how would i go about using say someones name instead of a number to comment about that particular name and if a different name is entered a different message would show?
Any help is appreciated, Thanks!
C++
#include<stdio.h>
#include<conio.h>

void main()

{
int grade;

printf("Enter Your Grade:");
scanf_s("%d", &grade);

     if (grade &gt;= 60)
     {
       printf("You passed");
     }
     else 
     {
      printf("Hard Luck You Failed");
     }
     _getch();
}
Posted
Updated 22-Jan-15 13:46pm
v2

1 solution

Words in C are character strings.
This will explain:
http://www.tutorialspoint.com/cprogramming/c_strings.htm[^]

and here:
http://www.tenouk.com/clabworksheet/labworksheet6.html[^]

So from this link:

C
// name is an array variable, more on this later...

// means reserve 65 bytes of storage including terminated

// string, '\0'

char  Initial, Name[65];

// some prompt to user...

printf("Input name, initial and deposit:\n");

printf("What is your name? ");

// read the user input and store the data at...

scanf("%64s", Name);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900