CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

Clearing a string variable

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   July 18, 2010, 16:07
Default Clearing a string variable
  #1
New Member
 
Join Date: Apr 2009
Posts: 6
Rep Power: 8
eshimshi is on a distinguished road
How can I clear a string variable in udf?
mystring="";
or
mysring='\0';
or
mystring[0]='\0',
don't work
Any ideas?
eshimshi is offline   Reply With Quote

Old   July 18, 2010, 17:54
Default
  #2
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 10
DoHander is on a distinguished road
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);
DoHander is offline   Reply With Quote

Old   July 20, 2010, 11:37
Default
  #3
New Member
 
Join Date: Apr 2009
Posts: 6
Rep Power: 8
eshimshi is on a distinguished road
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.
eshimshi is offline   Reply With Quote

Old   July 20, 2010, 19:32
Default
  #4
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 10
DoHander is on a distinguished road
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
DoHander is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
error in COMSOL:'ERROR:6164 Duplicate Variable' bhushas Main CFD Forum 1 May 30, 2008 04: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


All times are GMT -4. The time now is 18:43.