By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,604 Members | 1,444 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,604 IT Pros & Developers. It's quick & easy.

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

P: 10
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.
Nov 16 '06 #1
Share this Question
Share on Google+
3 Replies


sivadhas2006
100+
P: 142
Hi,

This may help your needs.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <string.h>
  3. #include <iostream.h>
  4. void main()
  5. {
  6.    char
  7.       szTemp[10];
  8.    int
  9.       nNumber = 0;
  10.  
  11.    strcpy(szTemp, "10");
  12.  
  13.    // Convert the string to number.
  14.    nNumber = atoi(szTemp);
  15.    cout << "The converted number is : " << nNumber;
  16.  
  17. }
  18.  
  19.  
Regards,
M.Sivadhas.
Nov 16 '06 #2

P: 10
Hi,

This may help your needs.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <string.h>
  3. #include <iostream.h>
  4. void main()
  5. {
  6.    char
  7.       szTemp[10];
  8.    int
  9.       nNumber = 0;
  10.  
  11.    strcpy(szTemp, "10");
  12.  
  13.    // Convert the string to number.
  14.    nNumber = atoi(szTemp);
  15.    cout << "The converted number is : " << nNumber;
  16.  
  17. }
  18.  
  19.  
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.
Nov 16 '06 #3

P: 60
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;
}
Nov 16 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.