473,770 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

basic C++ question, slighty confused too

2 New Member
I have a question about:

and i only know really basic c++ none of the really fancy stuff :(

How to convert integers into a string/character array?

and

How do I search for specific integers in the string/character array? (all the input is integers)

Any help is appreciated :)
Jul 12 '07 #1
4 1173
gpraghuram
1,275 Recognized Expert Top Contributor
I have a question about:

How to convert integers into a string/character array?

and

How do I search for integers in the string/character array?

Any help is appreciated :)
To convert integer to string u can use sprintf
sprintf(arr,"%d ",integer);

To search for a integer in string or char array
you have to go character by character and use isdigit to check if it is a number


Raghuram
Jul 12 '07 #2
Voli
2 New Member
To convert integer to string u can use sprintf
sprintf(arr,"%d ",integer);

To search for a integer in string or char array
you have to go character by character and use isdigit to check if it is a number


Raghuram

Thanks but can you explain it further ? and i updated/reworded my original post to make it more clear
Jul 12 '07 #3
devikacs
96 New Member
I have a question about:

and i only know really basic c++ none of the really fancy stuff :(

How to convert integers into a string/character array?

How do I search for specific integers in the string/character array? (all the input is integers)

Any help is appreciated :)
How to convert integers into a string/character array?

I guess Raghuram has explained that clearly enough

How do I search for specific integers in the string/character array? (all the input is integers)

Assume the following declaration

char str="345633";

you want to search the number 5 in this.

loop through str. Any string in c is a character array.
So str[0]='3', str[1]='4',etc
So, to find the number 5, you have to search for the character '5', ascii value 48+5
Jul 12 '07 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
If you are using C++, then use a stringstream:
Expand|Select|Wrap|Line Numbers
  1. int data = 1234;
  2. stringstream ss;
  3. ss << data;
  4. string str;
  5. ss >> str;
  6.  
and you are done.
Jul 12 '07 #5

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

Similar topics

9
3284
by: Tom | last post by:
Hey all, I've been planning to get myself started with DocBook for quite some time now, so when I unexpectedly encountered a task for which DocBook might actually be very useful, I thought I'd no longer wait. Some Googling pointed me to several beginner tutorials, and I chose to get myself going with the guide at http://rzserv2.fhnon.de/%7Elg002556/docbuch/
7
1726
by: asfwa | last post by:
I'm new to C++ and I have some basic questions. I have written an app that does some network stuff in a worker thread. The thread function requests something from the server, gets it and creates an object from the server response. Does this thread terminate/stop/die as soon as it completes its last line of code? Or do I have to do something to kill it? I am used to coding Java so I am totally unsure of what I have to do to "clean up"...
3
3865
by: Yodai | last post by:
Hi all... I have this project on an embbeded system where I've programmed a very simple dynamic web-server on C, which serves 1 connection at a time. I need to implement a basic authentication system. I've heard the easiest is to go for HTTP 1.1 authentication, but I don't know ho to implement it.... Can anybody give me some advice, guidelines on where to start? Thank's ...... oh, and happy new year!!
6
1313
by: pinorama123 | last post by:
I have an ASP.NET application that contains a few classes that I have built. One of my objects is a user object. I have a pretty basic question about how this would work. If I have multiple users logging into my application and using the user object do they all share the same object or does ASP.NET know that each user's object belongs to them? I'm seeing some strange behavior that leads me to believe when one user dimensions an instance...
21
1509
by: Roland | last post by:
The following issue is puzzling me: There are 2 ways of writing the code below: .... Dim fnt as Font = New Font(...) DrawString(myText, fnt,...) fnt.dispose(). or DrawString(myText, New Font(...),...)
2
1653
by: anuragch1 | last post by:
#include <stdio.h> void main() { static int i = 1; void cal(); printf("%d\n",i); cal(); } void cal()
5
1550
by: Vijay | last post by:
Hi All, I am not able to figure out what exactly happening in below code. what is control flow. Can anyone clear my confusion? Code: class A { public: A(){cout<<"In Constructor\n";}
3
1405
by: Tenowg | last post by:
Hey guys, I know this is probably a very easy, basic question, so feel free to direct me to a detailed answer. I have done some searches some some of the information I get is vague. In C#, the basic idea I understand is to store information in objects to be used by other objects later. So to say building blocks of the program. My question is this. If I Make Object A, and then Object B, and in Object B I set a variable (can't think of a way to...
2
1166
by: splendid9 | last post by:
Hi all, i have a very basic css question. I already have a big css file with lot of classes init. div.text label.full, div.text2 label.full, div.text3 label.full, div.text4 label.full { width: 152px;
0
9619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.