LinuxQuestions.org
Help answer threads with 0 replies.
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 07-12-2002, 02:22 PM   #1
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Rep: Reputation: 15
C vs Perl ( about s///g; )


Hi
I'm a perl prograMmer but I want to try out some C now.

Look at this simple exampel in perl
It will replace all h with H

$tmp = "hello out there";
$tmp = ~s/h/H/g;

output: Hello out tHere


How can I do this in C. I just searched the forum but I can't find anything about this.

Is the problem hard to solve i C ??


Thanks

//FredrikN
 
Old 07-12-2002, 02:44 PM   #2
dorward
Member
 
Registered: Sep 2001
Distribution: Gentoo
Posts: 760

Rep: Reputation: 31
http://www.ncbi.nlm.nih.gov/IEB/Tool...source/regexp/
 
Old 07-12-2002, 02:49 PM   #3
pickledbeans
Member
 
Registered: Jun 2002
Location: Bailey, CO
Distribution: Slackware
Posts: 483

Rep: Reputation: 32
I guess that sed -e 's/h/H/g' isn't the answer you looking for.... unless you could call sed from with C
 
Old 07-13-2002, 04:23 AM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Code:
#include <stdio.h>
#include <string.h>

int main(){
	int i=0;
	char tmp[]="Hello out there";
	printf("Before: %s\n",tmp);
	for(i=0;i<=strlen(tmp);i++)
		if(tmp[i]=='h') tmp[i]='H';
	printf("After: %s\n",tmp);
	return 0;
}
 
Old 07-13-2002, 10:14 AM   #5
FredrikN
Member
 
Registered: Nov 2001
Location: Sweden
Distribution: GNU/Linux since -97
Posts: 149

Original Poster
Rep: Reputation: 15
Oki, thanks

Works fine
 
  


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
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
chrooting apache v2 (php, ssl, perl support) ; perl configuration markus1982 Linux - Security 3 01-26-2003 06:15 PM
can i set ~/public_html/perl as a perl directory for apache? doublefailure Linux - Networking 1 07-09-2002 04:31 PM

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

All times are GMT -5. The time now is 09:34 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