Any idea how can i solve this problem? Messing around at google but, still don't know the solution ..
Attached thumbnail(s)
C++ c++ stuck, Can give any suggestion or help?
C++ c++ stuck, Can give any suggestion or help?
|
Oct 11 2016, 10:18 PM, updated 8y ago
Show posts by this member only | IPv6 | Post
#1
|
Junior Member
323 posts Joined: Apr 2015 From: Melaka |
|
|
|
|
Oct 11 2016, 10:22 PM
Show posts by this member only | Post
#2
|
Senior Member
2,641 posts Joined: Jan 2003 |
Position in string determine the number of spaces behind the character?
|
|
Oct 11 2016, 10:32 PM
Show posts by this member only | Post
#3
|
Junior Member
389 posts Joined: Dec 2008 |
Each character's index position in the string equal to the space in front of each character 's print out.
|
|
Oct 11 2016, 10:32 PM
Show posts by this member only | IPv6 | Post
#4
|
Junior Member
323 posts Joined: Apr 2015 From: Melaka |
|
|
Oct 11 2016, 10:33 PM
Show posts by this member only | Post
#5
|
Senior Member
661 posts Joined: Dec 2011 |
|
|
Oct 11 2016, 10:35 PM
Show posts by this member only | IPv6 | Post
#6
|
Junior Member
323 posts Joined: Apr 2015 From: Melaka |
|
|
Oct 11 2016, 10:36 PM
Show posts by this member only | Post
#7
|
Senior Member
2,641 posts Joined: Jan 2003 |
|
|
Oct 11 2016, 10:38 PM
Show posts by this member only | Post
#8
|
Junior Member
77 posts Joined: Jun 2011 |
Print space before you print the character
|
|
|
|
Oct 11 2016, 10:42 PM
Show posts by this member only | IPv6 | Post
#9
|
Junior Member
323 posts Joined: Apr 2015 From: Melaka |
QUOTE(Eventless @ Oct 11 2016, 10:36 PM) i still cant figure out the way to space infront of those character,,i only manage to print out character without spaces infront them.Below is what i done so far : cout << "Enter text : "; string txt; getline(cin,txt); int z = txt.length(); for (int i=0;i<=txt.length();i++) { cout << txt[i] << endl; } |
|
Oct 11 2016, 10:44 PM
Show posts by this member only | IPv6 | Post
#10
|
Junior Member
160 posts Joined: Nov 2008 |
here...
CODE #include <iostream> #include <iomanip> #include <string> using namespace std; int main(int argc, char** argv) { string s; cout << "Enter text ==> "; getline(cin, s); for (int i=0; i<s.length(); i++) { cout << setw(i+1) << s[i] << endl; } return 0; } |
|
Oct 11 2016, 10:48 PM
Show posts by this member only | IPv6 | Post
#11
|
Junior Member
323 posts Joined: Apr 2015 From: Melaka |
QUOTE(RookieDaddy @ Oct 11 2016, 10:44 PM) here... May i know this => (int argc, char** argv) CODE #include <iostream> #include <iomanip> #include <string> using namespace std; int main(int argc, char** argv) { string s; cout << "Enter text ==> "; getline(cin, s); for (int i=0; i<s.length(); i++) { cout << setw(i+1) << s[i] << endl; } return 0; } means what? |
|
Oct 11 2016, 10:52 PM
|
Senior Member
2,641 posts Joined: Jan 2003 |
QUOTE(beng970804 @ Oct 11 2016, 10:42 PM) i still cant figure out the way to space infront of those character,,i only manage to print out character without spaces infront them.Below is what i done so far : Create a new string with spaces and add the char end. Output the content of the new string.cout << "Enter text : "; string txt; getline(cin,txt); int z = txt.length(); for (int i=0;i<=txt.length();i++) { cout << txt[i] << endl; } http://www.cplusplus.com/reference/string/string/insert/ |
|
Oct 11 2016, 10:53 PM
|
Senior Member
2,641 posts Joined: Jan 2003 |
QUOTE(RookieDaddy @ Oct 11 2016, 10:44 PM) here... You shouldn't spoonfeed the answer here.CODE #include <iostream> #include <iomanip> #include <string> using namespace std; int main(int argc, char** argv) { string s; cout << "Enter text ==> "; getline(cin, s); for (int i=0; i<s.length(); i++) { cout << setw(i+1) << s[i] << endl; } return 0; } |
|
Oct 11 2016, 10:59 PM
Show posts by this member only | IPv6 | Post
#14
|
Junior Member
323 posts Joined: Apr 2015 From: Melaka |
QUOTE(Eventless @ Oct 11 2016, 10:52 PM) Create a new string with spaces and add the char end. Output the content of the new string. Btw,is this forum have any topic to discuss c++ problem so i no need to post a new topic in future?http://www.cplusplus.com/reference/string/string/insert/ |
|
|
|
Oct 11 2016, 11:06 PM
|
Senior Member
2,641 posts Joined: Jan 2003 |
|
|
Oct 11 2016, 11:07 PM
Show posts by this member only | IPv6 | Post
#16
|
Junior Member
323 posts Joined: Apr 2015 From: Melaka |
|
|
Oct 12 2016, 10:24 AM
|
Senior Member
661 posts Joined: Dec 2011 |
QUOTE(beng970804 @ Oct 11 2016, 10:35 PM) C program Version. Btw I'm 17 know how to code and electronics Self Learned but ayam don't get good scholarships because they see resultCODE #include <stdio.h> #include <string.h> void blank(); int main () { char in[300]; int sLength = 0; scanf("%s",in); sLength=strlen(in); int counter = 0; int j = 0; for (int i=0; i < sLength; i++) { printf("%c",in[i]); printf("\n"); counter= counter + 1; for ( j =0; j < counter; j++) { blank(); } } return 0; } void blank() { printf(" "); } This post has been edited by xboxrockers: Oct 12 2016, 10:27 AM |
|
Oct 12 2016, 10:30 AM
|
Senior Member
661 posts Joined: Dec 2011 |
QUOTE(beng970804 @ Oct 11 2016, 10:48 PM) argc is arguments counter means how many things you typed in terminal Exp: how are you is counted as 3 arguments argv is argument vector Exp you can access why you type in terminal, Exp : argv[0] will give you how argv[1] will give you are argv[2] will give you |
|
Oct 12 2016, 10:34 AM
|
Senior Member
751 posts Joined: Dec 2008 |
|
|
Oct 12 2016, 11:04 AM
|
Senior Member
4,463 posts Joined: Jan 2003 |
C shouldn't be that long. And scanf() choke on spaces.
CODE #include <stdio.h> int main() { int c, count=0; while ((c = getchar()) != '\n') printf("%*c\n", ++count, c); return 0; } |
Change to: | 0.0165sec
0.44
6 queries
GZIP Disabled
Time is now: 29th March 2024 - 10:03 PM |