GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Oct-2003, 09:08
CoreLEx CoreLEx is offline
New Member
 
Join Date: Oct 2003
Posts: 1
CoreLEx is an unknown quantity at this point

storing a token pointer as a string


Hello everyone,

New guy here. I've only just started learning C. I'm trying to write a program that tokenizes a string and then stores each token into a string (char[]). The token is a char pointer. Printing it to the screen without first dereferencing it is fine, as it displays the contents of its memory address. However, when I try to assign it to a string variable I get the error:

error C2440: '=' : cannot convert from 'char' to 'char [9]'

I'd appreciate any help. I've included my code below. The line with the error is in bold.

CPP / C++ / C Code:
char strTest[]="TRACKINGID: 1365 DATE: 20030901 TIME: 1200 ROUTE: 12 DRIVER: 005 STATUS: Nobody present";
	char transDate[9];
	int tokenCounter; //to keep track of tokens in a transaction

tokenCounter=0;

	// -- Tokenize single transaction line 
	char *token;
	token=strtok(strTest,":"); // : is delimeter, strTest string to be tokenized
	while(token!=NULL) //loop until last delimeter
	{
		token=strtok(NULL," "); //extract data between white spaces in token

		if(tokenCounter==0)
			transDate=*token;

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

		token=strtok(NULL,":"); //tokenize string 

		tokenCounter=tokenCounter+1;
	}

	return 0;


Thanks.
  #2  
Old 07-Oct-2003, 12:33
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
The problem is with this line:
CPP / C++ / C Code:
transDate=*token;
token is a pointer to a single character in the char array. It's not pointing to the whole chunk, just the first character. So you're placing a single character into the transDate array which'll take 9 chars, that's why it's failing to change a char to a char[9].

You've to loop through transDate to get the whole string to stick into the array.

GF
 
 

Recent GIDBlogUS Elections and the ?Voter?s Responsibility? by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Including Maps and strings?? maddie C++ Forum 17 05-Jul-2004 07:25
C++ Error that makes no sense! ArcticTiger C++ Forum 1 10-Nov-2003 08:14
convert long to pointer to char realpopeye C++ Forum 2 26-Sep-2003 11:22
string to double C++ calculus87 C++ Forum 2 18-Sep-2003 12:50

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:32.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.