argv to string

Dec 16, 2008 at 2:05pm
Hi, I am a absolute c beginner...

for now, I have the following problem:
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "aspell.h"

int main(int argc, const char *argv[]) 
{
  char word[81];

...

   fgets(word, 80, stdin)

now, I would like use argv [1] as value for word, so that i can call the function in a shell-script:

example testword

and fprint("word: %s ", word); prints out

word: testword

I've got no idea, how to do this...

thanks in advance...
Dec 16, 2008 at 2:49pm
You can use sprintf(word,"%s",argv[1]);

Here the C++ way:
1
2
3
4
5
6
#include <string>
int main(int argc, const char *argv[]) 
{
     std::string word = argv[1];
     return 0;
}
Last edited on Dec 16, 2008 at 2:52pm
Topic archived. No new replies allowed.