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

10
  • itoa?? There is no itoa in standard library Commented Apr 2, 2014 at 20:22
  • 3
    "Let me make it clear, I am working on C" Then why did you tag C++? Commented Apr 2, 2014 at 20:22
  • 1
    Reference Page "This function is not defined in ANSI-C and is not part of C++, but is supported by some compilers." Commented Apr 2, 2014 at 20:23
  • 1
    Which compiler/platform are you using? Do you have evidence that it has an itoa function? How did you link your code? Commented Apr 2, 2014 at 20:24
  • 3
    It isn't. There is an exit in stdlib but no ixet. Use sprintf, or, if you are feeling insecure, snprintf. Commented Apr 2, 2014 at 20:26

3 Answers 3

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);
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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);
    }
}
}

1 Comment

I tried sprint, which changed my looping somehow infinite. Its below code: #include <stdio.h> #include <string.h> #include <stdlib.h> 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 ); } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.