LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-13-2005, 02:21 AM   #1
salahuddin_66
Member
 
Registered: Jan 2004
Location: Dhaka, Bangladesh
Distribution: Debian, Gentoo
Posts: 283

Rep: Reputation: 30
strlen problem


could some one tell me why it is not working.
i am learning C.

thanks

Code:
#include <stdio.h>
#include <string.h>

void converge (char *targ, char *src);

int main (void)
{
	char target [80] = "XXXXXXXXXXXXXXXXXXXXXXXXXXX";

	converge (target, "This is a test of converge.");
	printf("Final string: %s\n", target);

	return 0;
}

void converge (char *targ, char *src)

{
	int i, j;
	printf ("%s\n", targ);
	for (i=0, j=strlen(src); i<=j; i++, j--)
{
	targ [i] = src [j];
	targ [i] = src [j];
	printf("%s\n", targ); 
					}
}
 
Old 11-13-2005, 03:43 AM   #2
TruongAn
Member
 
Registered: Dec 2004
Location: Vietnam (Việt Nam)
Distribution: Gentoo (desktop), Arch linux (laptop)
Posts: 728

Rep: Reputation: 33
Exactly, how do you mean when you said it didn't work?
We don't know what are you intend to do with these code, so we cannot say anythings.
The only strange I found that you have add two line
targ [i] = src [j];
Only one is enough, however it is not a problem, your code can work with two or more line

Last edited by TruongAn; 11-13-2005 at 03:48 AM.
 
Old 11-13-2005, 04:21 AM   #3
salahuddin_66
Member
 
Registered: Jan 2004
Location: Dhaka, Bangladesh
Distribution: Debian, Gentoo
Posts: 283

Original Poster
Rep: Reputation: 30
thanks a lot

now ok

it was showing

XXXXXXXXXXXXXXXXXXXXXXXXXXX

Final string:
salahuddin@debiantesting:~/C$

now ok
salahuddin@debiantesting:~/C$ ./a.out
XXXXXXXXXXXXXXXXXXXXXXXXXXX
TXXXXXXXXXXXXXXXXXXXXXXXXXX
ThXXXXXXXXXXXXXXXXXXXXXXXX.
ThiXXXXXXXXXXXXXXXXXXXXXXe.
ThisXXXXXXXXXXXXXXXXXXXXge.
This XXXXXXXXXXXXXXXXXXrge.
This iXXXXXXXXXXXXXXXXerge.
This isXXXXXXXXXXXXXXverge.
This is XXXXXXXXXXXXnverge.
This is aXXXXXXXXXXonverge.
This is a XXXXXXXXconverge.
This is a tXXXXXX converge.
This is a teXXXXf converge.
This is a tesXXof converge.
This is a test of converge.
Final string:This is a test of converge.

after

targ [i] = src [i];
targ [j] = src [j];
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
strlen() function problem in C++ sajith Programming 9 01-16-2006 09:14 PM
C++ question: strlen error!? Hady Programming 2 03-16-2005 05:08 AM
confused about strlen() mcd Programming 19 02-26-2005 08:04 PM
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration