name : get_value_of_str.c
copyright : 2012-05
author : hurryliu
date : 2012-05-24
description : this file is used to get number from a string.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/*global variables*/
int v1;
int v2;
int v3;
char TMP[64];
char sample_str[64];
void get_value_of_str(char str[]);
int main()
{
char sample_str[64] ={ "hello,2,3,4"};
// strcpy(sample_str[64],SAMPLE_STR);
get_value_of_str(sample_str);
printf("TMP:%s v1:%d v2:%d v3:%d\n",TMP,v1,v2,v3);
return 0;
}
void get_value_of_str(char str[])
{
// char tmp[100];
int i = 0;
int j = 0;
char data[10];
for(i=0;str[i]!='\0';i++)
{
if(str[i] == ',')
{
data[j] = i;
j++;
}
}
data[j] = '\0';
/*
for(j=0;data[j]!='\0';j++)
{
printf("%d\n",data[j]);
}
*/
strncpy(TMP,str,data[0]);
// printf("%s\n",TMP);
v1 = atoi(&str[data[0]+1]);
v2 = atoi(&str[data[1]+1]);
v3 = atoi(&str[data[2]+1]);
// printf("%d %d %d\n",v1,v2,v3);
}