I'm reading in very large numbers that may have unusual spacing... like 123 45 43657 4 And I need to store this number in an array of ints without all the spaces :) I'm really not very familiar with string manipulation so anything will help!!!
Printable View
I'm reading in very large numbers that may have unusual spacing... like 123 45 43657 4 And I need to store this number in an array of ints without all the spaces :) I'm really not very familiar with string manipulation so anything will help!!!
look good?Code:#include <stdio.h>
int main() {
int numbers[255];
int x = 0;
int numbers2[255];
int y= 0;
while(numbers[x] != '\0') {
if(numbers[x] != ' ') {
numbers2[y] = numbers[x];
++y;
}
++x;
}
return 0;
}
:) It looks exactly like what I was trying to do... just so much cleaner! I'll try it out... Thanks!!!
Read the input into a string (char array), then loop through each character, testing it with isdigit(), and then storing the number in the int array.
>>while(numbers[x] != '\0') {
Here, numbers[x] is unitialised. Also, if the data is in an int array, the its already number, so checking against ' ' is like checking against 32 (assuming ASCII).
Maybe something in here will help you.
Hammer, going by the way you suggested would that method index a number more than one digit or would it only index a one digit number? Would it treat 106 as 106 or as 1, 0, 6?
>>Read the input into a string (char array), then loop through each character, testing it with isdigit(), and then storing the number in the int array.
ADD::
until a chararacter is NOT a digit then increment the array index
if you know they are going to be a space then use
isspace()
Code:int CheckStringForPunctuation(HWND hWnd,char *sBuffer)
{
char sTempBuffer[L_STRING], sNewString[L_STRING], *pNew=NULL, *pOld=NULL;
int iLen=0;
iLen=lstrlen(sBuffer);
if(iLen>=L_STRING)
return FALSE;//not enough space
sprintf(sTempBuffer,"%s",sBuffer);
pOld=sTempBuffer;
pNew=sNewString;
while(*pOld != '\0')
{
while(ispunct(*pOld)) *pOld++;
while(isspace(*pOld)) *pOld++;
*pNew++=*pOld++;
}
*pNew='\0';
sprintf(sBuffer,"%s",sNewString);
return TRUE;
}
ANS: 1, 0, 6.Quote:
Originally posted by _Cl0wn_
Hammer, going by the way you suggested would that method index a number more than one digit or would it only index a one digit number? Would it treat 106 as 106 or as 1, 0, 6?
Maybe that is the requirement, at least thats how I read it. But as usual, its open to interpretation.