Click here to Skip to main content
15,912,329 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to maximize window Pin
hemlat20-Feb-09 21:54
hemlat20-Feb-09 21:54 
GeneralRe: how to maximize window Pin
hemlat20-Feb-09 22:11
hemlat20-Feb-09 22:11 
QuestionHow do I know status of a service in a remote machine ? Pin
SherTeks20-Feb-09 19:00
SherTeks20-Feb-09 19:00 
AnswerRe: How do I know status of a service in a remote machine ? Pin
«_Superman_»20-Feb-09 19:52
professional«_Superman_»20-Feb-09 19:52 
GeneralRe: How do I know status of a service in a remote machine ? Pin
SherTeks20-Feb-09 20:10
SherTeks20-Feb-09 20:10 
QuestionError Creating Device Enumerator....... Pin
shaina223120-Feb-09 16:47
shaina223120-Feb-09 16:47 
AnswerRe:Solution for Error Creating Device Enumerator....... Pin
shaina223120-Feb-09 18:27
shaina223120-Feb-09 18:27 
QuestionUgly C code Pin
meixiang620-Feb-09 13:16
meixiang620-Feb-09 13:16 
Following to my question yesterday, is there anything that can be done to clean up the c code below which works fine but looks ugly especially the strcat's? The program parses a file containing a list of files and then runs a command on each. I can do a similar thing in perl like this a couple of lines but in C its looks ugly and I think its because I am a newbie...any comments will be appreciated....

thanks in advance for everyones help


In perl:
#!/usr/bin/perl

while(<>){
chomp;
$cmd="qsub -P 9999 -wd -e $_\.error -b y /usr/local/projects/bin/program -i $_ -type p -terms -lookup -o $_\.qsub";
print "$cmd\n";
}



in C:


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>


int main(int argc, char *argv[])
{
char * cwd = getcwd(0,0);
char pro[10000];
char str[1000];
char* nl;

if (argc < 3) {
printf("\n\nPlease supply a file containing a list of single file names follow by project code\n");
exit(5);
}

FILE *f;
f = fopen(argv[1], "r");
if(!f) {
printf("Couldn't open file.txtn");
return 1;
}

while(fgets(str, 1000, f)) {
nl = strrchr(str, '\r');
if (nl) *nl = '\0';
nl = strrchr(str, '\n');
if (nl) *nl = '\0';

strcpy(pro, "qsub -P ");
strcat(pro, argv[2]);
strcat(pro, " -wd -e ");
strcat(pro, cwd);
strcat(pro, "/");
strcat(pro, str);
strcat(pro, ".error -b y /usr/local/projects/bin/program -i ");
strcat(pro, cwd);
strcat(pro, "/");
strcat(pro, str);
strcat(pro, " -type p -terms -lookup -o ");
strcat(pro, str);
strcat(pro, ".qsub");
printf (pro);
system(pro);
}
}
GeneralRe: Ugly code Pin
Luc Pattyn20-Feb-09 14:27
sitebuilderLuc Pattyn20-Feb-09 14:27 
AnswerRe: Ugly C code Pin
grzkas22-Feb-09 1:30
grzkas22-Feb-09 1:30 
GeneralRe: Ugly C code Pin
meixiang622-Feb-09 6:12
meixiang622-Feb-09 6:12 
GeneralRe: Ugly C code Pin
Stuart Dootson22-Feb-09 13:54
professionalStuart Dootson22-Feb-09 13:54 
GeneralRe: Ugly C code Pin
meixiang622-Feb-09 16:25
meixiang622-Feb-09 16:25 
QuestionSending mp3/pcm sample as payload Pin
septane20-Feb-09 6:39
septane20-Feb-09 6:39 
AnswerRe: Sending mp3/pcm sample as payload Pin
led mike20-Feb-09 8:32
led mike20-Feb-09 8:32 
GeneralRe: Sending mp3/pcm sample as payload Pin
septane20-Feb-09 18:12
septane20-Feb-09 18:12 
AnswerRe: Sending mp3/pcm sample as payload Pin
«_Superman_»20-Feb-09 15:49
professional«_Superman_»20-Feb-09 15:49 
QuestionGetProcAddress() question.... Pin
Member Ártemis20-Feb-09 6:00
Member Ártemis20-Feb-09 6:00 
QuestionRe: GetProcAddress() question.... Pin
David Crow20-Feb-09 6:21
David Crow20-Feb-09 6:21 
AnswerRe: GetProcAddress() question.... Pin
Member Ártemis20-Feb-09 7:17
Member Ártemis20-Feb-09 7:17 
GeneralRe: GetProcAddress() question.... Pin
David Crow20-Feb-09 7:23
David Crow20-Feb-09 7:23 
QuestionRe: GetProcAddress() question.... Pin
CPallini20-Feb-09 6:28
mveCPallini20-Feb-09 6:28 
AnswerRe: GetProcAddress() question.... Pin
Member Ártemis20-Feb-09 7:22
Member Ártemis20-Feb-09 7:22 
GeneralRe: GetProcAddress() question.... Pin
Mark Salsbery20-Feb-09 8:29
Mark Salsbery20-Feb-09 8:29 
GeneralRe: GetProcAddress() question.... Pin
led mike20-Feb-09 8:31
led mike20-Feb-09 8:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.