Jump to content

well guys i learned the c bases like 4 mouths ago because i forgot most of it i decided to get to a online course but fro mthe start he does things i never saw like this one 

#include <stdio.h>
#include <stdlib.h>

int main(int argc , char **argv)
{
    int i;
    for ( i=0; i<argc; i++){
    printf("Hello world argc=%d arg %d is %s  !\n",argc,i,argv[i]);
    }
    return 0;
}

so this code should ask me to put in some arguments and if for example i write 3 words in the console it will put 2 as a value for argc and then repeat printf like 3 times i don't have that when i launch the console , it just asks me to tap any thing and printf works only one time fpr info he uses codelite on ios i use code blocks on windows . if you don't understand i will take pictures of both consoles and codes 

Link to comment
https://linustechtips.com/topic/674675-c-bases/
Share on other sites

Link to post
Share on other sites

The code handles console arguments passed with application exe name like this:

Microsoft Windows [Wersja 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Wszelkie prawa zastrzeżone.

C:\Users\KoKa>app.exe argument1 arg2 three

There are 3 arguments and they're argument1, arg2, three

 

And the code does:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) // argc is number of arguments, for 3 arguments it will be 4 because exe name is passed as first argument
                                // argv is array of cstrings and it contains all those arguments, ["app.exe", "argument1", "arg2", "three"]
{
    int i;
    for (i = 0; i < argc; i++){ // This loop will execute argc times, so in this case 4 times as there are 3 arguments + exe name
    	printf("Hello world argc = %d arg %d is %s!\n", argc, i, argv[i]); // It will print out arguments count, current (i-th) argument index
                                                                           // and i-th argument value
    }
    return 0;
}

 

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8688803
Share on other sites

Link to post
Share on other sites

13 minutes ago, Mr_KoKa said:

The code handles console arguments passed with application exe name like this:


Microsoft Windows [Wersja 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Wszelkie prawa zastrzeżone.

C:\Users\KoKa>app.exe argument1 arg2 three

There are 3 arguments and they're argument1, arg2, three

 

And the code does:


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) // argc is number of arguments, for 3 arguments it will be 4 because exe name is passed as first argument
                                // argv is array of cstrings and it contains all those arguments, ["app.exe", "argument1", "arg2", "three"]
{
    int i;
    for (i = 0; i < argc; i++){ // This loop will execute argc times, so in this case 4 times as there are 3 arguments + exe name
    	printf("Hello world argc = %d arg %d is %s!\n", argc, i, argv[i]); // It will print out arguments count, current (i-th) argument index
                                                                           // and i-th argument value
    }
    return 0;
}

 

i used to have to use a hole sub fonctions to do things like this i mean i have to ask by myself the user then save the words he taped then count each argument using aski table so i add +1  to i each time i find a space and all this to just know the number of arguments that i have to write them one by one is a whole other story and now this guy puts 3 lines to do it . well i really don't understand the hell he did it's not at all how i used to do it can you explain more what is happening 

2- it don't work for me look 

argc.PNG

string.PNG

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8688891
Share on other sites

Link to post
Share on other sites

34 minutes ago, ilyas001 said:

well guys i learned the c bases like 4 mouths ago because i forgot most of it i decided to get to a online course but fro mthe start he does things i never saw like this one 

4 mouths ago? I think you should slow down on the plastic surgery.

ENCRYPTION IS NOT A CRIME

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8688917
Share on other sites

Link to post
Share on other sites

It doesn't work same way for you because you are running your app from your IDE, and IDE is not passing any additional arguments to your application,s o only one argument exists, and it is app execution path with exe name.

 

I guess you were just asking user to enter arguments on run time, using scanf or something similar.

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8688918
Share on other sites

Link to post
Share on other sites

3 minutes ago, Mr_KoKa said:

It doesn't work same way for you because you are running your app from your IDE, and IDE is not passing any additional arguments to your application,s o only one argument exists, and it is app execution path with exe name.

 

I guess you were just asking user to enter arguments on run time, using scanf or something similar.

ahh ok i get this now and how do i change this in codeblocks ? 

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8688935
Share on other sites

Link to post
Share on other sites

Just find directory that contains your executable, run command prompt from there by typing cmd into address field and pressing return. or user WINKEY-R and type cmd there then run it and change directory to directory that contains your exe, then just run your exe with arguments.

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8688951
Share on other sites

Link to post
Share on other sites

Just now, ilyas001 said:

and so what . i'm not even american ,we try like we can, sometimes i just write from google translate . sometimes i write very badlly  and i know that but i try 

It was a very poorly executed joke, just please excuse me while I fade away.

ENCRYPTION IS NOT A CRIME

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8689028
Share on other sites

Link to post
Share on other sites

26 minutes ago, Mr_KoKa said:

Just find directory that contains your executable, run command prompt from there by typing cmd into address field and pressing return. or user WINKEY-R and type cmd there then run it and change directory to directory that contains your exe, then just run your exe with arguments.

still not working i got into cmd taped my program name that was ilyas then arguments it says that ilyas is not an argument , why ? 

 

cmd.PNG

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8689103
Share on other sites

Link to post
Share on other sites

3 hours ago, straight_stewie said:

It was a very poorly executed joke, just please excuse me while I fade away.

I had a little giggle.

3 hours ago, ilyas001 said:

no problem if you think you insulted me . i'm used to , and i understand that my writing gives cancer i least you read it . it's a good sign 

Your English or Google's English is not nearly as bad as some people I have on Facebook and English is their native tongue.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8689939
Share on other sites

Link to post
Share on other sites

2 hours ago, ilyas001 said:

it worked thanks last question  why do i need to write .exe when he doesn't ? 

Microsoft stuff.

 

Now seriously, that's the way every single program works anyway, when you double-click a program's icon, you're sending to an OS console (cmd for Windows and bash for most linux) a code that sais "execute X program located in Y directory". In windows, those executable files are called ".exe", because that's the format that Windows recognizes for programs.

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8690075
Share on other sites

Link to post
Share on other sites

3 minutes ago, Train27 said:

Microsoft stuff.

 

Now seriously, that's the way every single program works anyway, when you double-click a program's icon, you're sending to an OS console (cmd for Windows and bash for most linux) a code that sais "execute X program located in Y directory". In windows, those executable files are called ".exe", because that's the format that Windows recognizes for programs.

i know but i was following a video and the guy didn't use .exe . that's why i was asking . i find that strage that never in my hole life a was able to follow a video and getting the same results as them  anyway people thank you  

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8690100
Share on other sites

Link to post
Share on other sites

Don't try to mimic a tutorial and expect to always get the same results. People have their own computer configurated "their way", and you can't know what he's done to his. Maybe he modified the console to recognize any unknown command as an executable file, saving the time to write ".exe" all the time (tho this is hellish dangerous), or maybe he was even using linux and you didn't notice (or some linux-emulated terminal).

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8690130
Share on other sites

Link to post
Share on other sites

8 minutes ago, Train27 said:

Don't try to mimic a tutorial and expect to always get the same results. People have their own computer configurated "their way", and you can't know what he's done to his. Maybe he modified the console to recognize any unknown command as an executable file, saving the time to write ".exe" all the time (tho this is hellish dangerous), or maybe he was even using linux and you didn't notice (or some linux-emulated terminal).

he used windows but i always get pretty angry when i don't work like i should like for exemple when he use the #define it gives him a warning that there is a problem once he change the variable it don't for me it just refuses to pass to form me #include is as powerfull as const commands anyway this is what makes the beauty of computing . we fight randomness lol 

Link to comment
https://linustechtips.com/topic/674675-c-bases/#findComment-8690190
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×