• Coding
  • ILIA_93's Helping Center

Well, at the end, i ended up in the engineering faculty, i wanted to go with computer science, but my parents were thinking in another direction, but still, i was a little happy when I found out that we have a computer science class in this faculty.
So let's get to it, I would love to go further in the C language and programming, so if you please, you can help me a little bit in here, for now my question will be soo naif, but....
So I started with this
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{puts("This fucking annoying worthless application, will help you know what hour will it be after a specific time given by you ( the lame user ), in condition that\nyou add the local time \n");
puts("WARNING!: Use the HH:MM:SS format when supplying the time to the system");
printf("Local time = ");
int H1, M1, S1;
scanf("%d:%d:%d",H1,M1,S1);
printf("You gave %d:%d:%d as local time\n",H1,M1,S1);
system("pause");
return 0;
}
The program is compiled, and then when it reachs the scanf line, i get "Run-Time Check Failure #3 - The variable 'S1' is being used without being initialized."
The same for 'M1' and 'H1', what that suppose to mean!
Ahh well before you use a variable, you have to declare it. In Visual Studio .net, for example, Dim is used to declare variables, for example Dim H1.
your scanf is wrong; scanf variable's address so their values can change.
should be : scanf(".. bla ..", &H1, &M1, &S1);
1) int H1 = int() did the trick
2) What the hell is this :"Unhandled exception at 0x56cfe42e (msvcr100d.dll) in 1.exe: 0xC0000005: Access violation writing location 0x00000000." After entering the numbers I got this :/
I don't think it's a code problem.
ILIA_93 wrote1) int H1 = int() did the trick
2) What the hell is this :"Unhandled exception at 0x56cfe42e (msvcr100d.dll) in 1.exe: 0xC0000005: Access violation writing location 0x00000000." After entering the numbers I got this :/
I don't think it's a code problem.
Oops, you're right, i forgot the address sign, "noob" :S
Thanks GN90
ILIA_93 wroteWell, at the end, i ended up in the engineering faculty, i wanted to go with computer science, but my parents were thinking in another direction, but still, i was a little happy when I found out that we have a computer science class in this faculty.
That's a bit off topic but I am really tempted to give a small advice about this issue. Do what you really love and what you are really passionate about. Life is too short for living someone else's life. If you want to succeed in your life follow what you think is the right thing for you. Thanks.
Short answer
You should use int H1=0;

Long answer
If you want to use a variable H1, you need to tell the compiler to "reserve" some space in memory that you will refer to as "H1".

Where should it be? Anywhere in the memory (the RAM) of your computer. It's your OS (Windows) who will decide.

How big should it be? It depends on the type of the variable you want to use.

You write int H1. So you ask for a space in memory of the size equivalent to int. Depending on your system that usually means 4 or 8 bytes. You can know the size on your system with the following code:
printf("%d\n", sizeof(int));
When you declare a variable, here's what happens:

C program - read "int H1"
C program - ask Windows: "Give me 4/8 bytes of memory"
Windows - replies to Cprogram : "Here's one. It starts at address 0x04f56bc8"
C program "Every time I read the variable H1, I will look for address 0x04f56bc8"

It is important that you understand that.

However there is a problem. We don't know what is written at address 0x04f56bc8. A previous program may have written anything, maybe malicious code.

This is why in C, the first thing you do when you declare a variable is to initialize it. That means write over the address 0x04f56bc8 with something we know is good.

In your case you want to initialize with a "neutral" integer. The common usage is to use 0. But it can be any variable you chose. For example:
int main()
{
    int a=100; // I initialized variable a to 100
    printf("%d", a);
}
:D Thank you very much rahmu, I don't want to be so annoying, but this is exactly what I'm looking for, I don't want to complete a working assignment, but learning about c++ language. So if anyone has some free time, next time I post a bump on my road, explain the real cause. I know that this is too much, but I donno, a simple idea every week, will surely make a difference by summer, and especially I'm looking to get a computer science master after I'm done with this.
But pointing out the mistake is more than enough, and thank you all for your help, and the biggest thank go to rahmu :) .

But it worked with only int H1, i forgot to put the "&" before the variable in scanf, but will use what you gave from now on, thanks again.
AymanFarhat wroteThat's a bit off topic but I am really tempted to give a small advice about this issue. Do what you really love and what you are really passionate about. Life is too short for living someone else's life. If you want to succeed in your life follow what you think is the right thing for you. Thanks.
:) , well it's nice to see some people still believe that life is all about happiness and success, some people were born with a good life, and others were not, so both sides should live with it. ( Don't ask me why, or tell me this is wrong :S )
@rahmu,

of all the explanations i have read on this subject, yours was the most clear and straightforward! +++++++++++++!!!
Thanks bash. It's not 100% accurate though. Try to keep in mind when is the variable expanded. Is it at compile time or at run time?
rahmu wroteThanks bash. It's not 100% accurate though. Try to keep in mind when is the variable expanded. Is it at compile time or at run time?
In every programming language, developers are told to initialize and declare and void but always forget to clarify as to why so. It isn't until you start managing the memory that you get the epiphany on the subject. The handling of the memory is what made programming languages such as java and interpreted scripts become more favored. C/c++ are of the most granular languages. But to sucked with such, you really need to know what you are doing.
The title rather sounds like you are running a helping center to help people , should be renamed to like "Help me center" or something :p
Nader.Sleiman wroteThe title rather sounds like you are running a helping center to help people , should be renamed to like "Help me center" or something :p
+1
LoL, thanks for the advice Nader. I'm helping people by letting them help me :p.
It's the moderators call anyways.

Back to topic, before I go any further in this, I'm using Visual Studio 2010 now, others are using borland ( something like that ), and the teacher told us to get ubuntus ( lamest operating system ever ). Should I proceed with VS10, or it's too much for my level?
ILIA_93 wrotethe teacher told us to get ubuntus ( lamest operating system ever ). ?
1- Your teacher is awesome for requesting this.
2- Change major.
ILIA_93 wroteLoL, thanks for the advice Nader. I'm helping people by letting them help me :p.
It's the moderators call anyways.

Back to topic, before I go any further in this, I'm using Visual Studio 2010 now, others are using borland ( something like that ), and the teacher told us to get ubuntus ( lamest operating system ever ). Should I proceed with VS10, or it's too much for my level?
Don't get a Ubuntu, stick to Windows.

Keep Visual Studio 2010, it's by far the best IDE you can ever work with. Get used to it, you'll fall in love with it just like the rest of us.
@ILIA_93:
First of all, I'm not going to change the title of the thread. It's a bit misleading but it's cute. Your post, your title.

Second of all. Give Ubuntu a try. Trust me. You are very lucky to have a teacher who's going to help you learn how to use it. Learning to use a linux OS and be comfortable with a command line is such an enlighting experience that it will make you a better programmer even if you end up never using it again.

Also, if it doesn't work out, and you can always go back to using Visual Studio. But keep this in mind: At one point or another in his career, every developer thinks "I want to try Linux/Ubuntu". Every programmer here on the forum did. Now you have a teacher to help you. Take advantage of it!

Also your teacher is a very wise man asking you to install it. I wish more teachers would do this (Not enough teachers in my school did anyway ... ). What uni do you go to?
get used to Ubuntu (or any other Linux) and compiling with gcc and using a command-line debugger such as gdb and a bit of Emacs. Just from a personal experience even if VS is awesome, simple to debug, one click to compile, .... , but there will be the time where you must use to other stuff. When I was at uni in Leb well for the simplicity we tended to use VS, Borland, ... and other IDE's because of their simplicity and no one obliged me to use linux; out of curiosity i wen beyond our usual simple linux command course but i didn't get lots of practice with all the command-line development things. When i moved to to my new University well all the PCs have Linux installed, no windows, all the C/C++ development was made using emacs, and compiled with gcc, ..... . And I had to be the fool for the first couple of hours as i finish my assignments but don't know how to write the makefile in order to compile or like i had this bug and had no idea how to debugg it, and i had to spend like a week reading tutorials and documentation and testing just to catch up.
So get used to it, even if you prefer the VS , it might be helpful someday and it might distinguish you from others (in your future job perhaps) .
Agreed with GN90.

If you're moving to Ubuntu, ask your teacher to help you with either emacs (strongly recommended) or Vim (a little more difficult in the beginning, but equally powerful).

You will soon realize how powerful these tools are.
Well you guys are the masters, I'll surely move to Ubuntu as soon as possible. But had anyone experienced problems in compatibility when using Ubuntu, like some windows frimware drivers and alikes wont work with Ubuntu, and what about overclocking?

I'm in LU-Hadath btw rahmu.