Code: Show/Hide verb()
{ char verb[20]; const char aprender[8]; int here; printf("Now type the verb:\n"); scanf("%s",&verb); switch(verb[20]) { case aprender[8]: { printf("Aprender means to learn/understand\n"); } return here; |
Code: Show/Hide if ( strcmp (language[10], "english") =="%c means %c",english spanish; |
Code: Show/Hide definition(char language[10], char english[25], char spanish[25]) { while { (strcmp(language,"english") == 0); } printf("%s = %s", english[25], spanish[25]); while { (strcmp (language, "spanish") ==0); } printf("%c means %c", spanish[25], english[25]); } return verb(); |
Code: Show/Hide void definition(char language[10], char english[25], char spanish[25]) { if (strcmp(language,"english") == 0) { printf("%s = %s", english, spanish); } else { printf("%s means %s", spanish, english); } } |
Code: Show/Hide char definition(char language[10], char english[25], char spanish[25])
{ if (strcmp(language,"english") == 0) { printf("%s = %s", english, spanish); } else { printf("%s means %s", spanish, english); } } |
Code: Show/Hide char definition(english[10], learn[25], aprender[25]); |
Code: Show/Hide variable_type variable_name[size]; |
Code: Show/Hide char string[10] = "english"; printf("string is '%s', string[1] is '%c', string[2] is '%c'\n", string, string[1], string[2]); |
Code: Show/Hide char definition(char language[10], char english[25], char spanish[25])
{ ... } |
Code: Show/Hide definition("english", "learn", "aprender"); |
Cyan~Fire wrote: |
I'm glad you're using printf(), continue to do so even though the tutorial uses cin/cout. |
Code: Show/Hide /*
Func Func+Child Hit Time % Time % Count Function --------------------------------------------------------- 0.290 48.2 0.290 48.2 10 complex_output(void) (etest.obj) 0.224 37.1 0.224 37.1 10 just_a_string_printf(void) (etest.obj) 0.081 13.4 0.081 13.4 10 just_a_string_puts(void) (etest.obj) 0.008 1.3 0.603 100.0 1 _main (etest.obj) */ #include <stdio.h> void just_a_string_printf() { printf("using printf\n"); } void just_a_string_puts() { puts("using puts "); } void complex_output() { printf("%s is the %d-best game in the world\n", "Continuum", 21); } int main() { int i; i = 10; while (i--) just_a_string_printf(); i = 10; while (i--) just_a_string_puts(); i = 10; while (i--) complex_output(); return 0; } |
Code: Show/Hide /*
Func Func+Child Hit Time % Time % Count Function --------------------------------------------------------- 2.741 75.8 2.741 75.8 10 complex_output(void) (etest_cout.obj) 0.873 24.1 0.873 24.1 10 just_a_string(void) (etest_cout.obj) 0.003 0.1 0.004 0.1 1 _$E25 (etest_cout.obj) 0.001 0.0 0.001 0.0 1 _$E22 (etest_cout.obj) 0.000 0.0 0.000 0.0 1 _$E28 (etest_cout.obj) 0.000 0.0 0.000 0.0 1 _$E23 (etest_cout.obj) 0.000 0.0 0.000 0.0 1 _$E24 (etest_cout.obj) 0.000 0.0 0.000 0.0 1 _$E29 (etest_cout.obj) 0.000 0.0 0.000 0.0 1 _$E30 (etest_cout.obj) 0.000 0.0 0.000 0.0 1 _$E31 (etest_cout.obj) 0.000 0.0 3.614 99.9 1 _main (etest_cout.obj) */ #include <iostream> using namespace std; void just_a_string() { cout << "using cout\n"; } void complex_output() { cout << "Continuum" << " is the " << 21 << "-best game in the world\n"; } int main() { int i; i = 10; while (i--) just_a_string(); i = 10; while (i--) complex_output(); return 0; } |
Brain wrote: |
Cyan, I've already tested the speed differences: http://forums.minegoboom.com/viewtopic.php?p=59625#59625 |
Brain wrote: |
I assume you didn't compile in release mode when you timed everything. |
Brain wrote: |
Cyan, you may find this link amusing: http://forums.minegoboom.com/viewtopic.php?p=28316#28316 |
BaK wrote: |
honestly, how much printing do your programs do? console output isn't the bottleneck in any resonable program; optimize where it matters. |
Animate wrote: |
Besides, I doubt it's really going to hurt me in the future if I never learn std::setiosflags. |
Code: Show/Hide /*
Func Func+Child Hit Time % Time % Count Function --------------------------------------------------------- 1915.341 100.0 1915.341 100.0 1 _main (brain_iostream.obj) 0.002 0.0 0.003 0.0 1 _$E25 (brain_iostream.obj) 0.001 0.0 0.001 0.0 1 _$E22 (brain_iostream.obj) 0.000 0.0 0.000 0.0 1 _$E23 (brain_iostream.obj) 0.000 0.0 0.000 0.0 1 _$E28 (brain_iostream.obj) 0.000 0.0 0.000 0.0 1 _$E29 (brain_iostream.obj) 0.000 0.0 0.000 0.0 1 _$E24 (brain_iostream.obj) 0.000 0.0 0.000 0.0 1 _$E30 (brain_iostream.obj) 0.000 0.0 0.000 0.0 1 _$E31 (brain_iostream.obj) */ /* Func Func+Child Hit Time % Time % Count Function --------------------------------------------------------- 914.573 100.0 914.573 100.0 1 _main (brain_printf.obj) */ |
Code: Show/Hide printf("Now type the verb:\n");
scanf("%s",&verb); if (strcmp (verb, "aprender")) { definition("english", "learn", "aprender"); } else (strcmp (verb, "beber")) { definition("english", "beber", "drink"); } else if (strcmp (verb, "comer")) { definition("english", "comer", "eat"); } |
Code: Show/Hide void definition(char language[10], char english[25], char spanish[25])
{ if (strcmp(language,"english") == 0) { printf("%s = %s\n", english, spanish); } else { printf("%s means %s\n", spanish, english); } return verb(); |
Code: Show/Hide Welcome to Scott's Beginner level translater, what
subject would you like to work on? 1.verbs 2.nouns 3.greetings 4.rules 5.Entire library 1 |==================================================| |Form Ar Verbs Er verbs Ir verbs Example=| |==================================================| |Yo--------o-----------o----------o--------hablo---| |Tu--------as----------es---------es-------halblas-| |El--------a-----------e----------e--------escribe-| |Ud.-------a-----------e----------e--------aprenede| |Ella------a-----------e----------e--------bebe----| |Uds.------an----------en---------en-------aprenden| |Ellos-----an----------en---------en-------comen---| |Ellas-----an----------en---------en-------leen----| |Nosotros--amos--------emos-------imos-----leimos--| |Nosotras--amos--------emos-------imos-----bebimos-| |==================================================| You've chose verbs. type a word and it will translate for you Now type the verb: aprender right here these two lines are awkward beber = drink and here these two lines are awkward Now type the verb: learn learn = aprender Now type the verb: |
Code: Show/Hide if (strcmp (verb, "aprender"))==[b]1[/b] |
Code: Show/Hide switch(verb)
case [b]1[/b]: { printf("aprender means to learn\n"); } |
tcsoccerman wrote: |
it annoys me you can't do switch statements with char's |
Code: Show/Hide if (!strcmp(input, "english"))
printf("You inputed English."); else if (!strcmp(input, "spanish")) printf("I'm sorry, I forgot Spanish a bunch of years back. Que pasa?"); else if (!strcmp(input, "backdoor")) printf("Welcome master, how many I do your bidding?"); else printf("ERROR 0x0000072"); |
Code: Show/Hide definition("english", "beber", "drink"); |
Code: Show/Hide definition("english", "comer", "eat"); |
Code: Show/Hide if (strcmp (verb, "aprender"));
{ definition("english", "learn", "aprender"); return here; } else if (strcmp (verb, "beber")); { definition("english", "beber", "drink"); return here; } else if (strcmp (verb, "comer")); { definition("english", "comer", "eat"); return here; } else printf("That word is unkown or spelled incorrectly, "remember to put a ""to"" in front of the word such as" """to learn"""); |
tcsoccerman wrote: |
MGB hit the answer right on the button though. |
Code: Show/Hide void definition2(char definition[100])
{ printf("Definition:%s\n", definition); } |
Code: Show/Hide void definition2(char definition[100]) |
Code: Show/Hide void definition2(char *definition) |
Code: Show/Hide #include <stdio.h> void definition2(char definition[100]) { printf("Definition:%s\n", definition); } int main() { definition2("apple"); return 0; } |
tcsoccerman wrote: |
probably a bug in compiler and debugger. where can i get a better one like msvc? |
unknown1988 wrote: |
If you can, learn C well, then move to C++. It is much easier to learn that way. If you wrote this same program in C++, you would be doing different things like passing by reference rather then by value which is very ugly. Even in C you should pass a pointer. Passing by a pointer is only putting 4 bytes on the stack rather than, in this case, an array with many elements (by value). |
Code: Show/Hide #include <stdio.h>
#include <string.h> void test(char str[20]) { strcpy(str, "bob smith"); printf("&str: %p [%p] str: %s\n", &str, str, str); } int main() { char str[20]; strcpy(str, "john jones"); printf("&str: %p [%p] str: %s\n", &str, str, str); test(str); printf("&str: %p [%p] str: %s\n", &str, str, str); return 0; } |
Code: Show/Hide &str: 0012FF6C [0012FF6C] str: john jones
&str: 0012FF1C [0012FF6C] str: bob smith &str: 0012FF6C [0012FF6C] str: bob smith |
Code: Show/Hide void definitions(string spanish, string english)
{ if (textbox.Text = "aprender"); { labeldef.Text = " aprender means to learn"; } |
Code: Show/Hide void ButtonClick(object sender, EventArgs e)
{ labeltitle.Text = textbox.Text; toolStripStatusLabel.Text = "Finding Definition..."; void definitions(aprender, english); |
Quote: | |
|
Code: Show/Hide if (condition)
{ } else { } for(int i = 0; i < n ; i++) { } while (condition) { } |
Code: Show/Hide void definitions(string spanish, string english)
{ if (textbox.Text == "aprender") { labeldef.Text = " aprender means to learn"; } |
Code: Show/Hide void ButtonClick(object sender, EventArgs e)
{ labeltitle.Text = textbox.Text; toolStripStatusLabel.Text = "Finding Definition..."; void definitions(aprender, english); |
Code: Show/Hide void ButtonClick(object sender, EventArgs e)
{ labeltitle.Text = textbox.Text; toolStripStatusLabel.Text = "Finding Definition..."; definitions(aprender, english); |