compare char with int in loop

Fjodor

my program is taking an argument which says how many prints that should be used. example of arguments: prints 2. I then want to loop through the value after prints, the number 2. and then print that many times. I tried like this:

for(i = 0; i < argv[2]; i++)
{
     ....

The problem is that argv is a char and i is an int. So when I run this loop, argv[2] aquire the value: 123123123 or something, instead of just 2. Is there any way around this or to compare the value in a char with an int. Thanks in advance

2501

argv[2] is a char* not a char. argv[2] points to a string( array of null terminated characters ). When you pass an arguments to you program, the argument is in that form.

You will have to convert it, you can use atoi() ;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

compare a char in char* with a loop

From Dev

How to compare int with char?

From Dev

compare int with char

From Dev

While loop and cin char, int

From Dev

Avoiding infinite loop when a char is enter in place of int

From Dev

How to compare char option with char

From Dev

How to compare char option with char

From Dev

some phenomenon of mysql query in where condition compare char filed with int 0

From Dev

Is it possible to compare a char with &char or &mut char?

From Dev

Is it possible to compare a char with &char or &mut char?

From Dev

Python compare char to hex

From Dev

compare const char * with strcmp

From Dev

Compare char in linq

From Dev

Compare a char to an array of chars?

From Dev

How to Compare a String with a Char

From Dev

How to compare a char?

From Dev

compare const char * with strcmp

From Dev

Compare char to user input char MASM

From Dev

fastest way to compare unsigned char* and const char*

From Dev

Compare user input (char) with other char

From Dev

Compare char to user input char MASM

From Dev

How to compare value in char array to another char

From Dev

cin for an int inputing a char causes Loop that is supposed to check input to go wild

From Dev

loading multiple arrays of char and int type in one while loop from a text file

From Dev

C++ Input a char instead of int lead to endless loop. How to check the wrong input?

From Dev

Compare with int and string in IF condition

From Dev

Properly compare IntPtr to int

From Dev

Compare two int arrays

From Dev

How to compare String with Int