1

Here is my code which uses itoa() function , seems not working. Let me make it clear, I am working on C.

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

void main()
{       
    int i,j;
    for(i = 0;i<= 4; i++)
    {
        for (j = 0; j <= 9; j++)
        {
            //printf("Hi\n");
            char fileName[10]="A";
            char append[2];

            itoa(i,append,10);
            strcat(fileName,append);    

            itoa(j,append,10);
            strcat(fileName,append);

            printf("i=%d j=%d\n", i,j);
            printf("%s\n", fileName);
            //FMS()             
        }
        //printf("Anuj=%d\n",i );
    }
}

Output

RC4Attack.c:(.text+0x5e): undefined reference to itoa' RC4Attack.c:(.text+0x8e): undefined reference toitoa' collect2: error: ld returned 1 exit status

suspectus
  • 16,548
  • 8
  • 49
  • 57
Pratik K. Shah
  • 397
  • 3
  • 17

3 Answers3

1

There's no itoa in standard C library. Instead, use sprintf.

sprintf(string_value, "%d", integer_value);

EDIT Use snprintf to guard against buffer overflow as well.

snprintf(string_value, max_size, "%d", integer_value);
avmohan
  • 1,820
  • 3
  • 20
  • 39
0

I had a similar issue two weeks ago,
I solved it by using sprtinf instead of itoa.

http://www.cplusplus.com/reference/cstdio/sprintf/


Did it look like this?

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

void main()
{  
int i,j;
for(i = 0;i<= 4; i++)
{
    for (j = 0; j <= 9; j++)
    {
        //printf("Hi\n");
        char fileName[10]="A";
        char append[2];

        sprintf(filename,"%s%d",fileName,i);    
        sprintf(filename,"%s%d",fileName,j);    

        printf("i=%d j=%d\n", i,j);
        printf("%s\n", fileName);
    }
}
}
evenro
  • 2,626
  • 20
  • 35
  • I tried sprint, which changed my looping somehow infinite. Its below code: #include #include #include int main() { int i,j; for(i = 0;i<= 4; i++) { for (j = 0; j <= 9; j++) { //printf("Hi\n"); char fileName[10]="A"; char append[1]; sprintf(append, "%d", i); strcat(fileName,append); sprintf(append, "%d", j); strcat(fileName,append); printf("i=%d j=%d\n", i,j); printf("%s\n", fileName); //FMS() } //printf("Anuj=%d\n",i ); } } – Pratik K. Shah Apr 02 '14 at 20:28
0

I can offer you 2 solutions:

1.) You could try to use a different c-compiler, some may work

2.) You could write this function easily yourself. Its only a small piece of code (see the following link) http://en.wikibooks.org/wiki/C_Programming/C_Reference/stdlib.h/itoa

Also you could use a former thread about this topic which may help in your case: Where is the itoa function in Linux?

Greetings Marius

Community
  • 1
  • 1
Schuiram
  • 191
  • 1
  • 1
  • 8