Recursion

This is a discussion on Recursion within the C Programming forums, part of the General Programming Boards category; Hello,
I encountered a problem with my code. Its doesn't print correctly. Here my output
[img]
http://img413.imageshack.us/img413/8392/outputgsv1.jpg
[/img]
and here's ...

I only want to print string that we choose which is auto assign to argv[4] in my code. if i use argv[4][0] then it only print the first character of the string in argv[4]. But i want the program to print the whole string in the data files.

What if x is the maximum number? You add one and call the same function again. So the first thing you need to do is

Code:

if(x > max) return;

I only want to print string that we choose which is auto assign to argv[4] in my code. if i use argv[4][0] then it only print the first character of the string in argv[4]. But i want the program to print the whole string in the data files.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

t8 t8data.txt <coordinate of x> <coordinate of y> <sentences to fill up any space according to x-y coordinate >

that's mean argv[4] = to the sentences because we use function argument. The problem is I can't make the program to print the whole string. If a character then it would be easy just assign char a=argv[4][0]; Then manipulate a little bit in fill function it would work. But for a string It's kinda tricky. That's my problem right now.

The problem is I can't make the program to print the whole string. If a character then it would be easy just assign char a=argv[4][0]; Then manipulate a little bit in fill function it would work. But for a string It's kinda tricky. That's my problem right now.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

But my lecturer said another extra fgetc(in) only need in UNIX to skip over newline

Well, your lecturer is wrong. A newline is a character. You need to skip it. It doesn't get skipped for you.

But maybe you just misinterpreted what your lecturer said. There is a difference between newlines under DOS and under Linux and under Macs. However, you don't need to worry about it if you open your file in text mode, which you do. (Actually, you do need to worry about line endings othat don't belong on the system, like DOS files under Linux. But let's just assume here that the line endings will be correct for your platform.)

Ya, my question is suppose to be like that. but can we directly pass the strcpy to function fill? And when you said I could actually pass argv[4] directly to fill, May I know how?

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

Well, your lecturer is wrong. A newline is a character. You need to skip it. It doesn't get skipped for you.

But maybe you just misinterpreted what your lecturer said. There is a difference between newlines under DOS and under Linux and under Macs. However, you don't need to worry about it if you open your file in text mode, which you do. (Actually, you do need to worry about line endings othat don't belong on the system, like DOS files under Linux. But let's just assume here that the line endings will be correct for your platform.)

OIC. Maybe u r right

Umm . . . it's just like you'd expect.

Code:

fill(x,y, argv[4], ArraySize);

I got error when compiling with this format.

if we use this format as a function call than in the header of function definition will be like this right

Well, you would get an error if you pass a string to a function that expects a char. Make both of them strings or both of them chars.

What do you want fill to do with its argument (a)? Do you want to fill everything with one character? If so, then pass one character with argv[4][0] and declare the function to take char a. If you want to somehow deal with all of the characters in argv[4] then pass argv[4] and make the function take char*a as its parameter.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

Well, you would get an error if you pass a string to a function that expects a char. Make both of them strings or both of them chars.

What do you want fill to do with its argument (a)? Do you want to fill everything with one character? If so, then pass one character with argv[4][0] and declare the function to take char a. If you want to somehow deal with all of the characters in argv[4] then pass argv[4] and make the function take char*a as its parameter.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

You need to check to see if x<0, y<0, and y>max too. And if an array has N elements, you want to check for x>=max, because C arrays are zero-based.

But can u please tell me the code that i should add to iterate each character

It's a little complicated. I guess that you want to increment the character you use when you travel right and decrement the character you use when you travel right, but use the same one if you go up or down. Assuming I'm right, you need an index of sorts to keep track of which character you are using, and wrap it as required. (If it gets below zero, add strlen(a), and vise versa.)

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

You need to check to see if x<0, y<0, and y>max too. And if an array has N elements, you want to check for x>=max, because C arrays are zero-based.

It's a little complicated. I guess that you want to increment the character you use when you travel right and decrement the character you use when you travel right, but use the same one if you go up or down. Assuming I'm right, you need an index of sorts to keep track of which character you are using, and wrap it as required. (If it gets below zero, add strlen(a), and vise versa.)

Ya. U R exactly right. If going right and down I can get it correctly. But left and up it will be reversible. Assuming I choose ABC, for left and down or should I say decrement it would be CBA. Is there anyway I can fix it.

Can u xplain more on "index of sorts to keep track of which character you are using, and wrap it as required". I'm not clear about that.