473,387 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.
Nov 16 '06 #1
3 7824
sivadhas2006
142 100+
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
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
seforo
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

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

Similar topics

4
by: DiggidyMack69 | last post by:
I have a sql resultset called columns. When I convert an integer column to string that is a NULL it converts to zero. How can I get it to convert to null?? String x; x =...
3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
12
by: Brian Henry | last post by:
first question... I have a flat file which unfortinuatly has columns seperated by nulls instead of spaces (a higher up company created it this way for us) is there anyway to do a readline with this...
14
by: Drew | last post by:
Hi All: I know I am missing something easy but I can't find the problem! I have a program which reads an integer as input. The output of the program should be the sum of all the digits in the...
20
by: Niyazi | last post by:
Hi all, I have a integer number from 1 to 37000. And I want to create a report in excel that shows in 4 alphanumeric length. Example: I can write the cutomerID from 1 to 9999 as: 1 ---->...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
5
by: Bob Homes | last post by:
In VB6, foreground and background colors of controls had to be assigned a single number. If you knew the RGB values for the color, you still had to convert them into the single number accepatable...
3
by: ryan.gilfether | last post by:
I have a problem that I have been fighting for a while and haven't found a good solution for. Forgive me, but my C++ is really rusty. I have a custom config file class: class ConfigFileValue...
3
by: =?Utf-8?B?U2hlbGRvbg==?= | last post by:
Hello - I have various times formatted like 00:00:00, so for example, 01:32:05 would be one thirty-two with five milliseconds. I need to convert this into seconds (an integer). First of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.