how to convert a string into integer value in c using typecast method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rayapati
    New Member
    • Oct 2006
    • 10

    how to convert a string into integer value in c using typecast method

    dear all,

    i had a problem in my program. that is we need to change the entire string into the positive integer value plase tell me how to do that one as soon as posible .

    thank you.
  • sivadhas2006
    New Member
    • Nov 2006
    • 142

    #2
    Hi,

    This may help your needs.

    Code:
    #include <string.h>
    #include <iostream.h>
    void main()
    {
       char
          szTemp[10];
       int
          nNumber = 0;
    
       strcpy(szTemp, "10");
    
       // Convert the string to number.
       nNumber = atoi(szTemp);
       cout << "The converted number is : " << nNumber;
       
    }
    Regards,
    M.Sivadhas.

    Comment

    • rayapati
      New Member
      • Oct 2006
      • 10

      #3
      Originally posted by sivadhas2006
      Hi,

      This may help your needs.

      Code:
      #include <string.h>
      #include <iostream.h>
      void main()
      {
         char
            szTemp[10];
         int
            nNumber = 0;
      
         strcpy(szTemp, "10");
      
         // Convert the string to number.
         nNumber = atoi(szTemp);
         cout << "The converted number is : " << nNumber;
         
      }
      Regards,
      M.Sivadhas.

      thanks for giving these code but these is not working in the C i want these to be work in C and iostream.h fileis not in the C. can you help me in these regard sir.

      thank you.

      Comment

      • seforo
        New Member
        • Nov 2006
        • 60

        #4
        Modifing it a little bit like this makes it work in c

        #include <string.h>
        #include <stdio.h>
        int main()
        {
        char szTemp[10];
        int nNumber = 0;
        strcpy(szTemp, "10");
        // Convert the string to number.
        nNumber = atoi(szTemp);
        printf("The converted number is : %d \n",nNumber);
        return 0;
        }

        Comment

        Working...