Re: [R] How to use character in C code?

2013-05-17 Thread Jan van der Laan


Characters in R are zero terminated (although I couldn't find that in 
the R extensions manual). So, you could use:



void dealWithCharacter(char **chaine, int *size){
  Rprintf(The string is '%s'\n, chaine[0]);
}

Jan



On 05/10/2013 03:51 PM, cgenolin wrote:

Hi the list,
I include some C code in a R function using .C. The argument is a
character.
I find how to acces to the characters one by one:
--- 8 --- C 
void dealWithCharacter(char **chaine, int *size){
  int i=0;
  for(i=0;i*size;i++){
Rprintf(Le caractere %i est %c\n,i,chaine[0][i]);
  };
}
--- 8 -- R -
ch - zerta
.C(dealWithCharacter,as.character(ch),as.integer(nchar(ch)))
--- 8 --

But is it possible to acces to the full word at once?

Christophe


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to use character in C code?

2013-05-10 Thread cgenolin
Hi the list,
I include some C code in a R function using .C. The argument is a character.
I find how to acces to the characters one by one:

--- 8 --- C 
void dealWithCharacter(char **chaine, int *size){
  int i=0;
  for(i=0;i*size;i++){
Rprintf(Le caractere %i est %c\n,i,chaine[0][i]);
  };
}
--- 8 -- R -
ch - zerta
.C(dealWithCharacter,as.character(ch),as.integer(nchar(ch)))
--- 8 --

But is it possible to acces to the full word at once?

Christophe



--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-use-character-in-C-code-tp4666757.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to use character in C code?

2013-05-10 Thread Suzen, Mehmet
You may want to use C++ instead using Rcpp which string handling would
be easier:
http://gallery.rcpp.org/articles/strings_with_rcpp/


On 10 May 2013 15:51, cgenolin cgeno...@u-paris10.fr wrote:
 Hi the list,
 I include some C code in a R function using .C. The argument is a character.
 I find how to acces to the characters one by one:

 --- 8 --- C 
 void dealWithCharacter(char **chaine, int *size){
   int i=0;
   for(i=0;i*size;i++){
 Rprintf(Le caractere %i est %c\n,i,chaine[0][i]);
   };
 }
 --- 8 -- R -
 ch - zerta
 .C(dealWithCharacter,as.character(ch),as.integer(nchar(ch)))
 --- 8 --

 But is it possible to acces to the full word at once?

 Christophe



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/How-to-use-character-in-C-code-tp4666757.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.