|
[Sponsors] |
July 18, 2010, 17:07 |
Clearing a string variable
|
#1 |
New Member
Join Date: Apr 2009
Posts: 9
Rep Power: 17 |
How can I clear a string variable in udf?
mystring=""; or mysring='\0'; or mystring[0]='\0', don't work Any ideas? |
|
July 18, 2010, 18:54 |
|
#2 |
Senior Member
Join Date: Nov 2009
Posts: 411
Rep Power: 20 |
char aux[20];
int i,n; strcpy(aux,"propusaurus"); printf("%s\n",aux); n=strlen(aux); for(i=0;i<n;i++)aux[i]=' '; printf("%s\n",aux); printf("%d\n",n); |
|
July 20, 2010, 12:37 |
|
#3 |
New Member
Join Date: Apr 2009
Posts: 9
Rep Power: 17 |
I tried it.
Unfortunately it didn't help. Using: for(i=0;i<n;i++)aux[i]=' '; just replaces the characters with spaces. when i append chars to the string with: strcat(aux,"-t.txt"); it adds them to the end of the spaces so that with each loop it gets longer. I need a way to reset the counter of the string. |
|
July 20, 2010, 20:32 |
|
#4 |
Senior Member
Join Date: Nov 2009
Posts: 411
Rep Power: 20 |
I think I know what you want, try this piece of code:
======================== int i,n; strcpy(aux,"propusaurus"); printf("Content = %s\tLength = %d\n",aux,strlen(aux)); /*Empty the string, reset the counter to 0*/ strcpy(aux,""); printf("Content = %s\tLength = %d\n",aux,strlen(aux)); ======================================== The call to strcpy will replace what is in aux with an empty string, the counter will be reset to 0, if you apply strlen you will see the empty string has zero characters in it. Hope this will help, Do |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
error in COMSOL:'ERROR:6164 Duplicate Variable' | bhushas | COMSOL | 1 | May 30, 2008 05:35 |
Problems with additional variable | Krishna Premi | CFX | 1 | October 29, 2007 09:19 |
How to update polyPatchbs localPoints | liu | OpenFOAM Running, Solving & CFD | 6 | December 30, 2005 18:27 |
Env variable not set | gruber2 | OpenFOAM Installation | 5 | December 30, 2005 05:27 |
Replace periodic by inlet-outlet pair | lego | CFX | 3 | November 5, 2002 21:09 |