Register and join over 40,000 other developers!
Recent Topics
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
-
Job Gig PHP Form Needed
PJohnson - Apr 18 2019 03:55 AM
-
How to make code run differently depending on the platform it is running on?
xarzu - Apr 05 2019 09:17 AM
-
How do I set a breakpoint in an attached process in visual studio
xarzu - Apr 04 2019 11:47 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

Transferring Data From String Array
Started by jasonalien, Jul 10 2012 12:33 AM
string array string array data integer
8 replies to this topic
#1
Posted 10 July 2012 - 12:33 AM
Hello everyone,
I have a string array with a length of 360 strings. But only a small amount of the strings are full, like 10-20 strings. And the data inside the strings is like that :
-91dBm
-93dBm
-88dBm
-89dBm
-88dBm
-89dBm
-92dBm
-91dBm
-92dBm
-90dBm
-90dBm
I need to make some calculations on this data. So How could I get rid of the dBms after numbers? And how could I conver them to negative integers.
Thanks in advance.
I have a string array with a length of 360 strings. But only a small amount of the strings are full, like 10-20 strings. And the data inside the strings is like that :
-91dBm
-93dBm
-88dBm
-89dBm
-88dBm
-89dBm
-92dBm
-91dBm
-92dBm
-90dBm
-90dBm
I need to make some calculations on this data. So How could I get rid of the dBms after numbers? And how could I conver them to negative integers.
Thanks in advance.
#2
Posted 10 July 2012 - 12:44 AM
You mean all those above data contains in a single array of char? Or, only one of them will be in a string at a time (as example -91dBm)?
If an array of chars contains data like "-91dBm", you can use atoi function go get the data. As example,
If an array of chars contains data like "-91dBm", you can use atoi function go get the data. As example,
int frequency = atoi("-91dBm"); /* here frequency variable will have -91 in it*/
#3
Posted 10 July 2012 - 04:52 AM
only one data is on one string, for example -91dBm is in one string.
#4
Posted 11 July 2012 - 08:42 PM
What kernel mentioned will still work in this case, did you manage to get it working though, bahadirtr?only one data is on one string, for example -91dBm is in one string.
I've returned...
#5
Posted 12 July 2012 - 11:25 PM
string yirmidorty[360] int baha[360]; for(int i = 0; i<360;i++) { baha[i]=atoi(yirmidorty[i]); cout<<baha[i]<<endl; }My compiler says that I'm giving invalid arguments to atoi.. As I see atoi accepts char array but not strings. Is there a way to make atoi do that?
Thanks..
#6
Posted 13 July 2012 - 12:07 AM
I found istringstream function. It seems useful but I couldn't make this code work :
int baha[360]; for(int i = 0; i<360;i++) { istringstream(yirmidorty[i])>>baha[i]; cout<<baha[i]<<endl; }
#7
Posted 16 July 2012 - 11:34 PM
I have never heard of the istringstream function before, if you wish to use it I'll look it up but to convert your string to a C string, simply use the function .c_str() on the string.
e.g.
e.g.
char * cString= (char*)yirmidorty[i].c_str();
I've returned...
#8
Posted 17 July 2012 - 04:20 AM
It's nice to write own function which is really simple.I wote my function which was changing string like 22-3+(31*3) to two stacks one integer type with values second char type with operators. In your case it would be much simplier cause you have to read from '-' till next digit is not integer.
function that checks would look really simple like :
You are comparing ASCII digits. Then you can append character to a temporary string where you'll have only numbers.
This is working prototype, I leave to you recognizing whenever its negative or positive int.
Edit : This is ms vc++ so to get this working youll need to include in stdafx.h:
Or just make propper includes in your IDE ;-)
Hope this was helpful,
notes.
function that checks would look really simple like :
if (((int)num[0] > 47) && ((int)num[0] <58) ) return true; return false;
You are comparing ASCII digits. Then you can append character to a temporary string where you'll have only numbers.
This is working prototype, I leave to you recognizing whenever its negative or positive int.
bool is_number(char c); int str_to_int(string str); int _tmain(int argc, _TCHAR* argv[]) { string str ="-96dBm"; int result = str_to_int(str); cout << "String: " << str<< "\nInt: " << result<< endl; system("PAUSE"); return 0; } bool is_number(char c) { if ( ((int)c > 47) && ((int)c <58) ) return true; return false; } int str_to_int(string str) { int myResult = 0; // IMPORTANT to initialize this int. string temp; int j = 1; // Want to start from 1 cause first char is '-' // You may want to change is_number function to omit this. while (is_number(str[j]) ) { temp += str[j]; j++; } // Now we have number in temp; int tempSize=temp.length()-1; for (int i = 0; i <tempSize; i++ ) { myResult*=10; // if 0 still 0 myResult+=atoi(&temp[i]); } return myResult; }
Edit : This is ms vc++ so to get this working youll need to include in stdafx.h:
#pragma once #include "targetver.h" #include <stdio.h> #include <tchar.h> #include <iostream> #include <string> using namespace std;
Or just make propper includes in your IDE ;-)
Hope this was helpful,
notes.
#9
Posted 17 July 2012 - 07:47 AM
thank you

Also tagged with one or more of these keywords: string array, string, array, data, integer
Language Forums →
C# →
Counting the integers frequences in an array entered by the userStarted by AndreMarques, 27 Nov 2017 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
Why is similar string comparison giving different result?Started by nick112, 29 May 2017 ![]() |
|
![]() |
||
Language Forums →
PHP →
How Come Variable Not Assigned And Php Knows Where To Look For Value ?Started by uniqueideaman, 06 May 2017 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
help me . c++. ArraysStarted by girl2383, 06 Feb 2017 ![]() |
|
![]() |
||
Language Forums →
Other Languages →
ASP, ASP.NET and Coldfusion →
Multiple dropdowns that share the same dataStarted by Tchpowdog, 20 Sep 2016 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download