C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-18-2009, 12:16 PM   #1
Registered User
 
Join Date: Nov 2009
Posts: 13
Regex Pattern Question

I'm working on a regex parser that sifts through an input file and matches a student's name to their grade.

Code:
char name[BUF_SIZE];

sprintf(name,argv[2]);     /*copy netid into name */
printf("Grade Info For '%s'\n\n",name);

sprintf(name_grade, "(\\-.[char name goes here]).\\|.([0-9]+)");
How can I get the 2nd sprintf line to regex match on the name stored in char name[] ?

The file input format is

Code:
 - studentname | 29
Thanks
surefire is offline   Reply With Quote
Old 11-18-2009, 12:40 PM   #2
Registered User
 
Join Date: Oct 2006
Location: Canada
Posts: 1,230
So if the given argument has name "bob", the regex should look like "- bob | ([0-9])+"?

Why dont you just print it?
Code:
sprintf(name_grade, "(\\-.%s).\\|.([0-9]+)", name);
Or whatever format it is--just use it as if you were "printf"ing.
nadroj is offline   Reply With Quote
Old 11-18-2009, 12:46 PM   #3
Registered User
 
Join Date: Nov 2009
Posts: 13
Awesome, didn't realize that was an option. Thanks!
surefire is offline   Reply With Quote
Old 11-18-2009, 12:48 PM   #4
Registered User
 
Join Date: Oct 2006
Location: Canada
Posts: 1,230
No problem. Keep in mind that "sprintf" and "fprintf" are the string- and file-output equivalents of screen-output "printf", respectively. So anything you can do in "printf", is just as easily done in the other functions.
nadroj is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
a sed and regex question lehe Linux Programming 1 09-03-2009 01:05 PM
Visitor / Decorator Pattern MarkZWEERS C++ Programming 9 05-16-2009 11:53 AM
Hmm.. Ai? Finding the pattern in number squences? Zeusbwr C++ Programming 8 04-02-2005 06:13 PM
Question... TechWins A Brief History of Cprogramming.com 16 07-28-2003 09:47 PM
(pattern *) pat & pattern * pat siubo C Programming 1 04-08-2003 10:03 PM


All times are GMT -6. The time now is 11:02 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22