| | |
Printing first letter of string
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 22
Reputation:
Solved Threads: 1
c Syntax (Toggle Plain Text)
#include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> void main() { char s[100],z[10]; clrscr(); cout<<"Enter your name:"; gets(s); cout<<strupr(s[0]); cout<<"."; getch(); }
what I am looking for is that when user input deniweb,then it should output D
please help
Thanks
•
•
Join Date: Oct 2009
Posts: 30
Reputation:
Solved Threads: 0
0
#2 Oct 23rd, 2009
If its a c string you could just print out the first element in the array
C++ Syntax (Toggle Plain Text)
cout << your_array[0]; // prints out first element of array
•
•
Join Date: Oct 2009
Posts: 22
Reputation:
Solved Threads: 1
0
#3 Oct 23rd, 2009
•
•
•
•
If its a c string you could just print out the first element in the array
C++ Syntax (Toggle Plain Text)
cout << your_array[0]; // prints out first element of array
Thanks
•
•
Join Date: Oct 2009
Posts: 30
Reputation:
Solved Threads: 0
-1
#4 Oct 23rd, 2009
Oh,well you could write a series of if/else if statements like
But that would be extremely long winded
C++ Syntax (Toggle Plain Text)
if(my_array[0]=='a' || 'A') cout << "A"; else if(my_array[0]=='b' || 'B') cout << "B";
But that would be extremely long winded
•
•
Join Date: Oct 2009
Posts: 63
Reputation:
Solved Threads: 16
0
#5 Oct 23rd, 2009
•
•
Join Date: Oct 2009
Posts: 22
Reputation:
Solved Threads: 1
0
#6 Oct 24th, 2009
•
•
•
•
Oh,well you could write a series of if/else if statements like
C++ Syntax (Toggle Plain Text)
if(my_array[0]=='a' || 'A') cout << "A"; else if(my_array[0]=='b' || 'B') cout << "B";
But that would be extremely long winded
Input------------>daniweb
Output---------->Ddaniweb
Thanks
0
#7 Oct 24th, 2009
C++ Syntax (Toggle Plain Text)
cout<<strupr(s[0]);
To solve this problem, You can do two things.
First, You can use the function toupper()
But you will need an additional header file
#include <ctype.h> or if you have a modern compiler #include <cctype> Or else if you wish to use strupr() itself, heres a little snippet..
C++ Syntax (Toggle Plain Text)
char temp[2]; temp[0]=s[0]; temp[1]='\0'; cout<<strupr(temp);
![]() |
Similar Threads
- Finding the first letter of each string in a list (Python)
- printing text file string contents (array) - padded characters (C++)
- Capitalize letter in string to output... Should be a pretty easy solution! (C)
- Code Snippet: Capitalize a letter of a string (PHP)
- remove a letter in a string (Python)
- How to count Uppercase Letter from a String (ASP)
Other Threads in the C++ Forum
- Previous Thread: pointers in friend function
- Next Thread: Could I get some help with this
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





