![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 4
![]() |
Ok, I will try to guess what you think...
if(argc!=2)
{ ----}I suppose that here you are trying to check if argc contains 1 argument. What would happen if the user entered more than two arguments? So, the correct way would be: if(argc == 1)
{ ----}Now, in the if - statement, do you want to check that i is equal to 4? If iso, if( i == 4 ) would work just fine. I hope that helps. |
|
|
|
|
|
#22 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Squirrel, please go back to using code tags. Ivan, some of us think he want to set this value with a command line argument, as when he invokes the program. Others think he wants to set the value with a command line argument when he invokes the COMPILER to compile the program. He hasn't addressed this issue. He has been given solutions if the first assumption is correct. He hasn't given any really definitive code snippets or expressed his needs clearly. It's all ambiguous. Good responses are difficult to come up with under the circumstances.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#23 |
|
Newbie
Join Date: Jun 2006
Posts: 11
Rep Power: 0
![]() |
No u got me wrong. May be i explained it wrong.
I have a program which has a if construct: fread(data,sizeof(data),1,fp_myfile);
if(data[0]=='8')&&(data[1]=='2'))
{
memcpy(&i,data+17,sixeof(int));
if(i == 4) // the value of "i" is not always same, so need to change the value of "i" eachtime i run the program
{
some commands;
}
else
{
some statements;
}
}This program is hardcoded, and i need to open the program and change the value of "i" always. I modified the program so that "i" can be taken as command line argument. I added some code lines as follows: int i;
---
---
if(argc!=2)
{
printf("Error at command line");
printf("Enter value if 'i' ");
}
i=atoi(argv[1]);
Now my problem is how do i change the if construct??
fread(data,sizeof(data),1,fp_myfile);
if(data[0]=='8')&&(data[1]=='2'))
{
memcpy(&i,data+17,sixeof(int));
if(i == ??) // what do I give here, like how do i change the if construct, bcoz the value is taken from command line, its a bit confusing??
{
some commands;
}
else
{
some statements;
}
}Hope the problem is understood. thanks Squirrel |
|
|
|
|
|
#24 |
|
Newbie
Join Date: Jun 2006
Posts: 11
Rep Power: 0
![]() |
DaWei -> Iam sorry for posting such unclear questions. But i guess I will learn it soon, as iam new in the forums.
|
|
|
|
|
|
#25 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Maybe understood. Let's presume you are now setting the value of i from the command line. Now you want to branch depending upon that value. If you don't know how your branch condition relates to the value, how the hell can we? Perhaps you could post a chart. If i is in the range blah:bleah, do this; otherwise, do that.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#26 |
|
Newbie
Join Date: Jun 2006
Posts: 11
Rep Power: 0
![]() |
Thankx for the help
|
|
|
|
|
|
#27 | ||
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
Quote:
Quote:
The use of 'if' is particularly simple, but without some idea of the logic behind the program, no one will be able to help you much. For starters what does "i" represent, what do you intend to decide based apon it and what will actions will be taken? How many valid values of your particular "i" are there?
__________________
-Steven "Is this a piece of your brain?" - Basil Fawlty Last edited by stevengs; Jun 27th, 2006 at 9:59 AM. |
||
|
|
|
|
|
#28 |
|
Programming Guru
![]() |
It's as simple as changing your question marks to an actual number that you want i to be compared to...
__________________
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|