• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

integer to string

How do you code this QB code below in TC??

i% =  3
A$ = "Test" + STR(i%)  ' << Test 3

STR & VAL... ^_^
0
Kuoster
Asked:
Kuoster
  • 3
  • 3
1 Solution
 
marcjbCommented:
num = 3;
/* a is a string */

sprintf(a, "Test %i", num);
0
 
KuosterAuthor Commented:
Thanks! I never thought that it would be that easy.

Have a very happy Y2K!
0
 
marcjbCommented:
Thank you, and a Happy New Year to you!
0
Identify and Prevent Potential Cyber-threats

Become the white hat who helps safeguard our interconnected world. Transform your career future by earning your MS in Cybersecurity. WGU’s MSCSIA degree program was designed in collaboration with national intelligence organizations and IT industry leaders.

 
KuosterAuthor Commented:
One more question, what can I do if I want to write something like this??

a$ = a$ + STR$(3)
0
 
marcjbCommented:
I'm not familiar with QB, but it looks like you are trying to add something to an existing string.  If that is the case, you have two options.

1) If you are adding a string to another string, use the strcat function.

2) If you want to add a number to a string, copy the original string to a temporary string, and then use sprintf.

The reason you copy to a temporary string is that according to the C Standard, you cannot use the same string as both the target and source with sprintf.
For example, the following will compile, but may cause your program to crash.
sprintf(aString, "%s %i", aString, aNum);

So, given an array of characters called aString, a temporary array called aTemp, and a number aNum, you could do the following:

strcpy(aTemp, aString);
sprintf(aString, "%s%i", aTemp, aNum);
0
 
KuosterAuthor Commented:
thanks ^^
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now