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

Clearing a string variable

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 18, 2010, 17:07
Default Clearing a string variable
  #1
New Member
 
Join Date: Apr 2009
Posts: 9
Rep Power: 17
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, 18:54
Default
  #2
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 20
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, 12:37
Default
  #3
New Member
 
Join Date: Apr 2009
Posts: 9
Rep Power: 17
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, 20:32
Default
  #4
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 20
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


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 Off
Pingbacks are On
Refbacks are On


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


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