Re: Cannot return values of char variable
- From: Prasad <noname@xxxxxxxxx>
- Date: Fri, 03 Nov 2006 17:33:05 +0530
Pedro Pinto wrote:
Ok, here it goes.<problem description and code snippet sniped>
For your implementation of the divide function , i have created the following test case (which I guess was what Mark was asking you to do).
#include <stdio.h>
#include <stdlib.h>
void divide(char search_string[], char *array[], char *delimiter){
int loop;
array[0]=strtok(search_string,delimiter);
if(array[0]==NULL)
{
printf("No test to search.\n");
exit(0);
}
for(loop=1;loop<50;loop++)
{
array[loop]=strtok(NULL,delimiter);
if(array[loop]==NULL)
break;
}
for(loop=0;loop<50;loop++)
{
if(array[loop]==NULL)
break;
//printf("\nDivide - array[%d] = %s", loop,array[loop]);
}
}
int main(void) {
int i = 0 ;
char *arr[50];
divide("this,is,comma,separated,string", arr ,",");
printf("Divided contents\n");
for(i = 0; i < 50; i++)
{
if(arr[i]==NULL)
break;
printf("%s \n", arr[i]);
}
return 0;
}
Compilation :
Microsoft (R) 32-bit C/C++ Standard Compiler Version 13.00.9466 for 80x86
Copyright (C) Microsoft Corporation 1984-2001. All rights reserved.
sample.c
sample.c(6) : warning C4047: '=' : 'char *' differs in levels of indirection from 'int'
sample.c(16) : warning C4047: '=' : 'char *' differs in levels of indirection from 'int'
Microsoft (R) Incremental Linker Version 7.00.9466
Copyright (C) Microsoft Corporation. All rights reserved.
/out:sample.exe
sample.obj
Execution Result :
Divided contents
this
is
comma
separated
string
I am not sure what you want to return from divide function.
--
Prasad
.
- Follow-Ups:
- Re: Cannot return values of char variable
- From: Pedro Pinto
- Re: Cannot return values of char variable
- References:
- Cannot return values of char variable
- From: Pedro Pinto
- Re: Cannot return values of char variable
- From: T.M. Sommers
- Re: Cannot return values of char variable
- From: Pedro Pinto
- Re: Cannot return values of char variable
- From: mark_bluemel
- Re: Cannot return values of char variable
- From: Pedro Pinto
- Cannot return values of char variable
- Prev by Date: Re: Cannot return values of char variable
- Next by Date: Re: Cannot return values of char variable
- Previous by thread: Re: Cannot return values of char variable
- Next by thread: Re: Cannot return values of char variable
- Index(es):
Relevant Pages
|
|