If I input BD+05 378, the code knows what do to converting it to BD%2B+378 but if I enter vega, strtok returns vega and not NULL
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, const char * argv[]) {
// http://simbad.u-strasbg.fr/simbad/sim-basic?Ident=vega&submit=SIMBAD+search
char *star, *path, *simbad, c, *token, plus = '+', *tmpstar;
int offset, i;
float Vmag;
FILE *file;
star = (char *)calloc(30, sizeof(char));
tmpstar = (char *)calloc(30, sizeof(char));
path = (char *)calloc(250, sizeof(char));
simbad = (char *)calloc(250, sizeof(char));
do
{
strcpy(path,"'http://simbad.u-strasbg.fr/simbad/sim-basic?Ident=");
printf("input star name or q to quit:\n");
i = 0;
fscanf(stdin,"%c", &c);
while (c != '\n')
{
star[i++] = c;
fscanf(stdin,"%c", &c);
}
star[i] = '\0';
if ((token = strtok(star,&plus)) != NULL)
{printf("%s\n", token);
strcpy(tmpstar, token);
strcat(tmpstar, "%2B");
token = strtok(NULL,&plus);
printf("%s\n", token);
strcat(tmpstar, token);
strcpy(star, tmpstar);
}
i= 0;
while (star[i++] != '\0')
if (star[i-1] == ' ')
star[i-1] = '+';
printf("%s\n", star);
if (strcmp(star,"q") == 0)
return(99);
strcat(path,star);
strcpy(simbad, "curl ");
strcat(simbad,path);
strcat(simbad,"&submit=SIMBAD+search' > simbadout.txt ");
system(simbad);
strcpy(simbad,"grep \"<INPUT TYPE=\\\"hidden\\\" NAME=\\\"Coord\\\" VALUE=\\\"\" simbadout.txt > line.txt");
system(simbad );
if ((file = fopen("./line.txt", "r")) == NULL)
printf("file not opened\n");
fseek(file, 46, SEEK_SET);
fgets(star,30,file);
printf("%s\n",star);
fclose(file);
strcpy(simbad,"grep -b Fluxes simbadout.txt > line.txt");
system(simbad );
if ((file = fopen("./line.txt", "r")) == NULL)
printf("file not opened\n");
fscanf(file,"%d",&offset);
printf("%d\n", offset);
fclose(file);
if ((file = fopen("./simbadout.txt", "r")) == NULL)
printf("file not opened\n");
fseek(file, offset, SEEK_SET);
// fgets(star,30,file);
// printf("%s\n",star);
// for (i = 0; i < 200; i++){
fscanf(file,"%c", &c);
while (c != 'V')
fscanf(file,"%c", &c);
fscanf(file,"%c", &c);
while (c != 'V')
fscanf(file,"%c", &c);
fscanf(file,"%c", &c);
fscanf(file,"%s", star);
printf("%s\n", star);
}
while(strcmp(star,"q") != 0);
return (0);
}