|
|
Why do you need dumps. Dumps are the worst thing when it comes to certification. they take away the motivation for studies and i as i keep saying(learning is what matters the most in our profession)
|
|
|
|
|
Can be obtained?
Generally storage devices.
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
|
Hi,
What would be the best way to extract an array of strings (only the first strings separated by a "," ) encapsulated within the curly braces ( { } )from within a file...?
Eg: Test.txt
***************************
This is also in the text file
{ abc def ghi ,
jkl mno pqr ,
stu vwl yza ,
}
This is also in the text file
*****************************
I only want "abc" "jkl" and "stu" in an array..
Thanks,
Faez
|
|
|
|
|
What have you done so far??
|
|
|
|
|
int main()
{
char *buf[1024], *tok;
FILE *fp1, *fp2;
fp1=fopen("test.txt","r+");
fp2=fopen("newtest.txt","w+");
while(fgets(buf, bufsize, fp1) != NULL)
{
for(tok = strtok(buf,"{");tok !="}";)
{
fprintf(fp2, "%s",buf);
}
}
fclose(fp2);
fclose(fp1);
}
modified 10-Feb-12 0:03am.
|
|
|
|
|
Please use <pre> tags round your code (you can edit the above message) as it makes it so much easier to read.
Your call to strtok() should use a pattern of all the characters you wish to ignore, you can then use the first returned token on each line, something like:
while(fgets(buf, bufsize, fp1) != NULL)
{
tok = strtok(buf,"{ ,}");
if (tok != NULL)
printf("Token: %s\n", tok);
}
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Did you really intend for buf to be an array of pointers?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Well spotted!
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Lovely..! This program works like a charm.... But now I am getting some extra unwanted strings too till the point I wanto extract the needed string..
My new o/p file now look like
Token: DCLGEN
Token: LIBRARY
Token: ACTION
Token: LANGUAGE
Token: NAMES
Token: QUOTE
Token: COLSUFFIX
Token: IS
Token: EXEC
Token: POLICY_NO
Token: REG_NO
Token: EFFECTIVE_DATE
Token: EXPIRY_DATE
Token: CAN_EFF_DATE
Token: CAN_PRO_DATE
Token: RETURN_PREMIUM
Token: CAN_PROCESSED
Token: END-EXEC
But I want the strings only after EXEC and before END-EXEC... ie from POLICY_NO to CAN_PROCESSED... I tried using
while(strcmp("EXEC",tok))
but it ain't working .. :-/
Thanks in advance,
Faez
modified 10-Feb-12 0:05am.
|
|
|
|
|
Try this:
BOOL bCapture = FALSE; while(fgets(buf, bufsize, fp1) != NULL)
{
tok = strtok(buf,"{ ,}");
if (tok != NULL)
{
if (bCapture == FALSE)
{
if (strcmp(tok, "EXEC") == 0)
bCapture = TRUE;
}
else {
if (strcmp(tok, "END-EXEC") == 0)
bCapture = FALSE;
else
printf("Token: %s\n", tok);
}
}
}
[edit]Fixed the "END-EXEC" string, thanks to Carlo for pointing it out.[/edit]
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
modified 10-Feb-12 6:56am.
|
|
|
|
|
My 5, though your code, as it stands, wouldn't match the-requirements.
Veni, vidi, vici.
|
|
|
|
|
I wrote it over breakfast; what's missing?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Nothing is missing, however an underscore is not an hyphen.
--Carlo The Nitpick.
Veni, vidi, vici.
|
|
|
|
|
CPallini wrote: Carlo The NitpickEagle-Eye
FTFY
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
That code was a beauty again ....
Actually... the final file after strtok() looks like the one below...
Token: DCLGEN
Token: LIBRARY
Token: ACTION
Token: LANGUAGE
Token: NAMES
Token: QUOTE
Token: COLSUFFIX
Token: IS
Token: EXEC
Token: POLICY_NO
Token: REG_NO
Token: EFFECTIVE_DATE
Token: EXPIRY_DATE
Token: CAN_EFF_DATE
Token: CAN_PRO_DATE
Token: RETURN_PREMIUM
Token: CAN_PROCESSED
Token: END-EXEC
Token: COBOL
Token: DCLCANCL
Token: POLICY_NO
Token: CN-POLICY-NO
Token: REG_NO
Token: CN-REG-NO
Token: EFFECTIVE_DATE
Token: CN-EFFECTIVE-DATE
Token: EXPIRY_DATE
Token: CN-EXPIRY-DATE
Token: CAN_EFF_DATE
Token: CN-CAN-EFF-DATE
Token: CAN_PRO_DATE
Token: CN-CAN-PRO-DATE
Token: RETURN_PREMIUM
Token: CN-RETURN-PREMIUM
Token: CAN_PROCESSED
Token: CN-CAN-PROCESSED
Token: THE
Your code cleverly extracted the strings within EXEC and END-EXEC which I stored in
char tableCol[6][10]
But now I am finding it really difficult to store the strings which are immediatedly followed by the "tabCol" string from the file...
ie CN-POLICY-NO, CN-REG-NO, CN-EFFECTIVE-DATE, CN-EXPIRY-DATE, CN-CAN-EFF-DATE, CN-CAN-PRO-DATE, CN-RETURN-PREMIUM & CN-CAN-PROCESSED which are to be stored in
char tableRow[6][10]
Apologies ...
Thanks a ton,
Faez
|
|
|
|
|
Since they all begin with "CN-", you could add a test:
if (strncmp(tok, "CN-", 3) == 0)
printf ...
Alternatively you have to test for each one individually.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
No no... It ain't always preceeded with "CN-" string ...
The strings which needs to be stored in TabRow array are followed by the second occurrence of each tableCol values...
Initially I also thought of using strcat () and append CN- to the tabCol values...
But den I realized that it was for this file only... Other files are completely different.
Regards,
Faez
|
|
|
|
|
If you don't have a common character identifier to select your strings then there is little that can be done. And from what you say you will have different rules for different files so it's difficult to suggest any other options.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Finally I have come up witha Not-so-good code... But it works..
I created another similar situation to parse from END-EXEC to End of File as below...
if (k == 0)
{
if (strcmp(tok, "END-EXEC") == 0)
k = 1;
}
else
{
if (strcmp(tok, "THE") == 0)
{
k = 0;
}
else
{
strcpy(tabRow[m],tok);m++;
fprintf(fp3,"Token: %s\n", tok);
}
}
}
}
j=0,n=0;
for(j=0;j<=m;j++)
{
if(strcmp(tabCol[n],tabRow[j])==0)
{
k=j;
strcpy(tabRow[n],tabRow[k+1]);
n++;
}
else ;
}
for(k=0;k<n-1;k++)
{
printf("No %d Element under TableCol is = %s\n", k+1,tabCol[k]);
printf("No %d Element under TableRow is = %s\n", k+1,tabRow[k]);
}
It wud be nice to get ur comments on this...
Thanks,
Faez
|
|
|
|
|
Difficult to say really. Assuming it does what you want then that's fine, but I don't see any checks for the specific strings after the "END-EXEC" that you wish to save. Or perhaps that is what the line
if(strcmp(tabCol[n],tabRow[j])==0)
is doing.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Faez Shingeri wrote: ...which are to be stored in
char tableRow[6][10] Which won't be large enough.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
hi,
i have application that disply USB cemera video .for that i have to connect with samplegraber and get image anyone please hehp me.
|
|
|
|
|
Please do not post the same question in multiple forums.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|