|
Programming and Assembly Language Please read this Topic's rules!! |
![]() |
| LinkBack | Thread Tools | Rate Thread |
| ||||
Ok, thanks for that gizmo. here's my complete code, some of the comments are there so that i can re-insert it if needed. Code: #include <stdio.h> int main() { char this_is_a_string[128]; printf( "Welcome to AuthentiLog.\nTo initiate the login procedure\npress the enter key.", this_is_a_string ); getchar(); printf( "User name: " ); scanf( "%s", this_is_a_string ); printf( "welcome %s.\n", this_is_a_string ); char input_errora[128]; scanf( "%30s", this_is_a_string ); /*------ if ( "%30s", this_is_a_string ); printf( "\nInvalid Input, please enter a value less than 30 characters long\n", input_errora ); ------*/ char magic_string[128]; printf( "Password: ", magic_string ); scanf( "%s", &magic_string ); getchar(); printf( "Thankyou. ", magic_string ); char input_errorb[128]; scanf( "%30s", magic_string ); /*------ if ( "%30s", magic_string ); printf( "\nInvalid Input, please enter a value less than 30 characters long\n", input_errorb ); ------*/ char sir_madam[128]; printf( "\nPlease enter verification string: " ); scanf( "%s", sir_madam ); getchar(); printf( "Thankyou.", sir_madam ); getchar(); char input_errorc[128]; scanf( "%30s", sir_madam ); /*------ if ( "%30s", sir_madam ); printf( "\nInvalid Input, please enter a value less than 30 characters long\n", input_errorc ); ------*/ char number_list_confirm[128]; printf( "Please confirm the details below are correct.\n" ); printf( "UserName: %s.\n", this_is_a_string ); printf( "Password: %s.\n", magic_string ); printf( "Verification: %s.\n", sir_madam ); getchar(); char enter_pin[128]; printf( "please enter a pin number to confirm that they are correct.\n" ); printf( "PIN:", enter_pin ); scanf( "%s", enter_pin ); printf( "\nYou entered %s\n", enter_pin ); printf( "Press the enter key to confirm.\n\n" ); getchar(); char input_errord[128]; scanf( "%30s", enter_pin ); /*------ if ( "%30s", enter_pin ); printf( "\nInvalid Input, please enter a value less than 30 characters long\n", input_errord ); ------*/ /*--- scanf( "%s", magic_string ); printf( "PassNumber: %s", magic_string ); getchar(); scanf( "%s", sir_madam ); printf( "Verification Number: %s", sir_madam ); getchar(); ---*/ char string_final[128]; //this code is wrong------->printf( "\n", this_is_a_string ); //printf("%s\n", this_is_a_string); getchar(); printf( "Thankyou for using AuthentiLog %s.", this_is_a_string ); printf( "\nGoodbye %s.", this_is_a_string ); getchar(); } Edit: I've sorted it out, if you enter more than 30 characters, it spreads into the password and verification field. i'll post source later if anyone wants it. Now i'm really happy because i'm really getting the hang of it, thanks to everyone, especially gizmo for the help with learning.
__________________ i7 2600K (4.3Ghz 1.34v) | GTX580 | 16GB (4x4GB) Patriot Viper Sec. 5 Ser. 2 (1866 - 9-11-9-27) | P67A-UD4-B3 Corsair AX1200 | Vertex II 240GB SSD | 4TB RAID0 (Samsung HD204UI) | Logitech G930 Wireless Headset YouTube - Benchmark Results (Coming Soon!) Last edited by skool h8r; 25th August, 2005 at 05:03 PM. |
| ||||
Quote:
|
| ||||
Quote:
If you use a framework class library like MFC or OWL (Borland's Object Windows Library, which I still love) all of this housekeeping stuff is done for you so that you can focus on the task at hand. |
| ||||
ah right. I know about the messages as when making Re-volt setup file, there were advanced options using calls and messages. Sounds a bit like my mobile/cell phone. I didn't use them but i am going to start lerning how to make windows apps soon. When i'm comfortable with C, i'll learn C++ but until then, learning C is my objective.
__________________ i7 2600K (4.3Ghz 1.34v) | GTX580 | 16GB (4x4GB) Patriot Viper Sec. 5 Ser. 2 (1866 - 9-11-9-27) | P67A-UD4-B3 Corsair AX1200 | Vertex II 240GB SSD | 4TB RAID0 (Samsung HD204UI) | Logitech G930 Wireless Headset YouTube - Benchmark Results (Coming Soon!) |
| ||||
Right, i'm having problems with 'else' statements. here's what i've got so far: Code: if( "%s" == "scott"); printf( "You have the same name as the programmer of this application!\n"); else printf("welcome %s.\n", this_is_a_string);
__________________ i7 2600K (4.3Ghz 1.34v) | GTX580 | 16GB (4x4GB) Patriot Viper Sec. 5 Ser. 2 (1866 - 9-11-9-27) | P67A-UD4-B3 Corsair AX1200 | Vertex II 240GB SSD | 4TB RAID0 (Samsung HD204UI) | Logitech G930 Wireless Headset YouTube - Benchmark Results (Coming Soon!) Last edited by skool h8r; 25th August, 2005 at 07:11 PM. |
| ||||
Quote:
is an empty statement. The semicolon terminated the if statement, as it terminates all statements in 'C' and C++. You then followed that with the printf. If you had gotten the code to run, you would have discovered that the printf always executed, because you closed the if statement. The compiler then encountered the else clause, but had no if statement to associate it with. Here's what you wanted to write: Code: if( "%s" == "scott") printf( "You have the same name as the programmer of this application!\n"); else printf("welcome %s.\n", this_is_a_string); Code: if(0 == stricmp(this_is_a_string, "scott")) printf( "You have the same name as the programmer of this application!\n"); else printf("welcome %s.\n", this_is_a_string); Code: if(!stricmp(this_is_a_string, "scott")) printf( "You have the same name as the programmer of this application!\n"); else printf("welcome %s.\n", this_is_a_string); |
| ||||
Also, a couple of notes on coding style. Every programmer develops a style of coding over a period of time that allows them to produce the most code with the least errors. There are some generally accepted style guides for each language, and 'C' is no exception. However, remember that they are guides, not rules. They exist because they have been found to be the most effective for most people. It is OK to disregard them or change them, but think about it very carefully before you do so. Now, the style issue: The following code is perfectly legal, and will compile Code: if(!stricmp(this_is_a_string, "scott")) printf( "You have the same name as the programmer of this application!\n"); else printf("welcome %s.\n", this_is_a_string); Code: if(!stricmp(this_is_a_string, "scott")) printf( "You have the same name as the programmer of this application!\n"); printf("Because of this, you to be proclaimed as a great person!\n"); else printf("welcome %s.\n", this_is_a_string); Code: if(!stricmp(this_is_a_string, "scott")) { printf( "You have the same name as the programmer of this application!\n"); printf("Because of this, you to be proclaimed as a great person!\n"); } else printf("welcome %s.\n", this_is_a_string); The other thing is, notice how I structured the test in the if statement? Let's use a different piece of code: Code: #define ONE 1 #define TWO 2 int something = ONE; if(something == ONE) printf("One\n"); if(something = TWO) printf("Two\n"); This all comes about because C uses == for comparison and = for assignment. There are a lot of debates about whether this is a good or bad thing, which we needn't get into here. However, to avoid this problem, I do the following: Code: #define ONE 1 #define TWO 2 int something = ONE; if(ONE == something) printf("One\n"); if(TWO = something) printf("Two\n"); |
| ||||
Right, is it possible to have a 'time-delay' style thing? Like if i want to write 'loading...' and then have it add a full stop every second for a set amount of full stops e.g. add one full stop per second and then after it has printed 5 full stops to the screen, write another message such as 'loading complete'. I am considering using the 'timer' function in time.h to do this but don't know if it will work. I know it is a little bit more advanced but i'm sure it can be done. I've got the idea of if and else statements now, thanks again gizmo.
__________________ i7 2600K (4.3Ghz 1.34v) | GTX580 | 16GB (4x4GB) Patriot Viper Sec. 5 Ser. 2 (1866 - 9-11-9-27) | P67A-UD4-B3 Corsair AX1200 | Vertex II 240GB SSD | 4TB RAID0 (Samsung HD204UI) | Logitech G930 Wireless Headset YouTube - Benchmark Results (Coming Soon!) |
| ||||
You can use the Windows sleep() function to surrender control back to the OS for some period of time, but you have to include windows.h to use it, and your app is no longer portable. The only other way I know of would be to simply sit in a loop and call the clock() function until the specified time period has elapsed. As far as printing the dots is concerned, that's easy. So, you would do something like this: Code: #include <time.h> #include <stdio.h> int main() { clock_t ctTime; printf("waiting"); ctTime = clock(); ctTime += CLOCKS_PER_SEC; int nNumStops = 5; do { nNumStops--; printf("."); //empty while loop here //just to waste time while(ctTime < clock()); } while(nNumStops > 0);//this while is actually a clause for the do loop } Last edited by Gizmo; 25th August, 2005 at 09:20 PM. |
| ||||
Ah right, i get it now. I've finished the program for now and i'll post it in the morning. Once again, thanks gizmo for all the help, now i've got the basics of it, i think i can start to work up from where i am now. And to think, it all started with me requesting a png dll! I can't make one yet but i can make something unique in C. Thanks, Scott.
__________________ i7 2600K (4.3Ghz 1.34v) | GTX580 | 16GB (4x4GB) Patriot Viper Sec. 5 Ser. 2 (1866 - 9-11-9-27) | P67A-UD4-B3 Corsair AX1200 | Vertex II 240GB SSD | 4TB RAID0 (Samsung HD204UI) | Logitech G930 Wireless Headset YouTube - Benchmark Results (Coming Soon!) |
| ||||
If you have the Posix subsystem loaded they do (mostly), but that is part of the resource kit and has to be specifically installed, so it isn't on most systems. As far as what specifically is supported, I do not know, as I've never used it. Knowing MS I would say that it is the bare minimum required to be considered 'Posix Compliant'. |
| ||||
Don't worry mate you'll get used to how if/then/else if/else statements work even if it is a bit annoyinh at first. I prefer my simple delphi as i don't have to use stupid bracket's even if it does look cleaner i use Begin and End. Im pretty sure for a basic Windows gui you include <windows> or <windows.h> depends on the compiler but most just take the name without the extension these days. If you wan't to start on a windows gui best find a source code example of a skeleton one that explains bit by bit. It took me hours to find one when i wanted to have a go at it but i found a good example eventually. I think it's also always a good thing to indent if statment's in by one line unless inside another in which case you indent one line further. And unless an if is indented thus far i usually indent commands by 4 lines. Makes the code much more readable, extra spacing after some if statement's can help too so you don't put something in the wrong place for example: Code: If () Then Begin If() Then Begin If () Then Begin End; //Extra line here so you know where the if end's incase code need be put here later. End; //Same here. End;
__________________ |
| ||||
I like a lot of white space in my code. My indents are one tab and I leave two carriage returns between functions. Only function names are at position 1, all executable code starts with 1 tab input. It's a work of art ![]() Mind you, I only really program 8051 (and now derivatives) assembler. I have the kit for 6800 and 6502 but haven't looked at it yet.
__________________ It is by coffee alone I set my mind in motion... |
| ||||
Right, here's the improved version i promised yesterday. i've only just got online because i've been out all morning sorting out some shoes for school and a few other things. Anyway, the program is attached. I've put in messages that make it look like it copies files to memory but it doesn't, it's just to make it look more 'realistic'.
__________________ i7 2600K (4.3Ghz 1.34v) | GTX580 | 16GB (4x4GB) Patriot Viper Sec. 5 Ser. 2 (1866 - 9-11-9-27) | P67A-UD4-B3 Corsair AX1200 | Vertex II 240GB SSD | 4TB RAID0 (Samsung HD204UI) | Logitech G930 Wireless Headset YouTube - Benchmark Results (Coming Soon!) |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Rate This Thread | |
| |
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
linux help required | skool h8r | OS, Software, Firmware, and BIOS | 5 | 31st July, 2006 05:10 AM |
New Athlon Cpu Required | surgeon | AMD Motherboards & CPUs | 15 | 18th November, 2005 05:29 PM |
More mentions required | dod | ThunderRd's AOA FOLDING@HOME Team | 4 | 8th October, 2004 08:47 PM |