Helping ordinary people create extraordinary websites!

Go Back   Web Development Forum > Website Programming > Server-Side Scripting
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-16-2005, 06:02 AM
Junior Member
 
Join Date: Aug 2005
Posts: 1
Default Help pls, pointer to arrays

Hi, im trying to find out of the content of the file is a number, not a number(operator/ char) and invalid number.

number = 12, -14 etc
not a number = +, -, /, *, da, etc
invalid number = -144dad, 4i02d, etc

i managed to print the number and not a number out but i just can't figure how to get the invalid number...

the problem is as follows
read content of file,
break the content into words; using strtok, delimiter is 'white space'
now the problem im facing is how do one put the 'tokenPtr' into an array?

Im thinking of, after breaking into words, but the word into one array . However im facing a problem, initializer must be constant.

After breaking each word into 'letters,numbers or operators'.
use atoi to change each 'letters,numbers or operators' into a integer. it will return a integer if integer but return 0 if it is a letter or operator.

i add all the individual parts of the array.
if array= 0, then it is not a number.
if array is 1 or more , it is a number.

another problem im facing if the number(from content of the file) is 0, it will return not a number..

i can't seem to set the content of pointer tokenPtr into another array either.

some1 help pls?

thanks in advance.

the code i come up so far.

i assume each word has a maximum of 4 size.


Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>



int main()
{
FILE * mFile; /* mFile is myfile.txt file pointer */
char string [100]; /* string array */
const char *tokenPtr; /* tokenPtr is a pointer to a char */


mFile = fopen ("myfile.txt" , "r"); /* open file for reading*/
if (mFile == NULL) perror ("Error opening file"); /*if mFile is empty, error opening file*/
else {

fgets (string , 100 , mFile);
puts (string);

tokenPtr = strtok( string, " ");

while( tokenPtr != NULL ){


printf("\n%s\n", tokenPtr );


int i[]= atoi( tokenPtr );

for(int a=0; a<4; a++) {
if( i[a]*4 == 0 )
printf("Not a number\n");
else{
printf("Number\n",);
}


tokenPtr = strtok( NULL, " ");

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Arrays and Databases focus310 Server-Side Scripting 2 12-08-2007 07:13 PM

All times are GMT -5. The time now is 09:34 AM.


Website Design by Ducani Media Group
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.