|
Hi,
Is there a built-in string function to insert a # to all the lines which starts with string READ and ends with .(period)
Eg:abc.txt
asadf
sdf
READ abc asdj ads
asdkl asdj
djshf .
EOF
followed by substituion of a string..
Thanks in advance
|
|
|
|
|
try to use CStdioFile::ReadString to read one line once.
|
|
|
|
|
Need to code it in C
|
|
|
|
|
So what do you have so far? You'll find far more people willing to critique existing code than those willing to do your work outright for you.
"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
|
|
|
|
|
I shall henceforth post the code instantly while asking a new question next time
BTW here is my code and I think am lost...
#include <stdio.h>
#include <string.h>
#define MAX_LEN_SINGLE_LINE 120
#define bufsize 1024
int main()
{
char fileOrig[32] = "test.txt";
char fileRepl[32] = "myReplacedFile.txt";
const char text2find[80] = " READ ";
const char text2repl[80] = "# READ ";
int c, line=0;
char buffer[MAX_LEN_SINGLE_LINE+2];
char *buff_ptr, *find_ptr, *tok;
FILE *fp1, *fp2;
size_t find_len = strlen(text2find);
fp1 = fopen(fileOrig,"r+");
fp2 = fopen(fileRepl,"w+");
int i;
while(fgets(buffer,MAX_LEN_SINGLE_LINE+2,fp1))
{
buff_ptr = buffer;
while ((find_ptr = strstr(buff_ptr,text2find)))
{
while ((c = fgetc(fp1)) == '.')
{
if (c == '\n')
fputc("#",fp2);
else ;
}
while(buff_ptr < find_ptr)
fputc((int)*buff_ptr++,fp2);
fputs(text2repl,fp2);
buff_ptr += find_len;
}
fputs(buff_ptr,fp2);
}
fclose(fp2);
fclose(fp1);
return 0;
}
Thanks in advance,
Faez
modified 1-Mar-12 6:56am.
|
|
|
|
|
How about something a tad smaller, like:
BOOL bPrefix = FALSE;
while(fgets(buffer, sizeof(buffer), fp1))
{
if (strncmp(buffer, "READ", 4) == 0)
bPrefix = TRUE;
else if (buffer[strlen(buffer) - 1] == '.')
bPrefix = FALSE;
if (bPrefix)
fputc('#', fp2);
fputs(buffer, fp2);
} I've not tested it, but hopefully you get the idea.
"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
|
|
|
|
|
There are no changes in the new file at all
Also, there are multiple instance of READ such as END-READ etc whose line should not be precceded with #
I aint understanding how the current file pointer can be incremented till a "\n" or "."
|
|
|
|
|
Faez Shingeri wrote: There are no changes in the new file at all
Use the debugger to step through the code line by line to see what is happening along the way.
Faez Shingeri wrote: Also, there are multiple instance of READ such as END-READ etc whose line should not be precceded with #
The code snippet I provided only precedes those lines that start with READ.
Faez Shingeri wrote: I aint understanding how the current file pointer can be incremented till a "\n" or "."
fgets() internally increments the file pointer.
"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
|
|
|
|
|
Nothing helped... Tried alot of trial and error but the o/p refuses to roll out as expected..
|
|
|
|
|
It's working great now .. Thnx alot for help
|
|
|
|
|
So what did you end up with (to get it all going)?
"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
|
|
|
|
|
while(fgets(buffer,MAX_LEN_SINGLE_LINE+2,fp1))
{
buff_ptr = buffer;
strcpy(buffer2,buffer);
i = 0;
while( i++ < strlen(buffer))
{
if(isspace(buffer[i]))
continue;
strcpy(buffer2,&(buffer[i]));
break;
}
if(strncmp(buffer2,"READ",4) == 0)
{
found = true;
sprintf(buffer1,"# %s",buffer);
fputs(buffer1,fp2);
}
else if(found == false)
{
fputs(buffer,fp2);
}
else
{
sprintf(buffer1,"# %s",buffer);
fputs(buffer1,fp2);
if(strstr(buffer,".") != NULL)
found = false;
}
}
Alot of thanks to Chandrakantt also in helping me in this one..
|
|
|
|
|
No, there isn't. However it should be relatively simple to implement yourself.
Veni, vidi, vici.
|
|
|
|
|
Dear all
I want to impllement a uniform raycasting in a selected sphere region of a volume and want to calculate the intensity of each voxel that is traversed by a ray, I want to program in open gl,
can any one help me how I can do it?
any help from you appreciate alot.
Best
|
|
|
|
|
Can use DeviceIoControl for retriving data about an USB storage device (flash or hard drive) like: manufacturer, type, revision?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hi,
For retrieving the manufacturer, type and revision... you can probably use the IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION and populate a USB_DEVICE_DESCRIPTOR struct.
Best Wishes,
-David Delaune
|
|
|
|
|
I found IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION and USB_DEVICE_DESCRIPTOR in WIN_DDK, but I don't work with that environment because I'm not so advanced. Is it possible in VC++ and/or MFC?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
RomTibi wrote: Is it possible in VC++ and/or MFC?
Yes, Absolutely.
|
|
|
|
|
Thx 4 quoting me but I really need 2 know how to do it
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hi,
Why do you need someone to show you how to do this? What have you tried so far? Did it succeed or fail?
It looks like all you need to do is create a USB_DEVICE_DESCRIPTOR structure and call DeviceIoControl with the IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION control code.
Best Wishes,
-David Delaune
|
|
|
|
|
I've tested in VC++10:
- declared locally the COMCTL for IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION
- declared locally the structure USB_NODE_CONNECTION_INFORMATION
and DeviceIoControl() returned NULL. GetLastError() returned ... 50 ERROR_NOT_SUPPORTED .
Can you tell me why? pls
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hi,
With that error... it sounds like you are sending the control code to the wrong device. What handle are you passing to DeviceIoControl?
I would suggest that you use this sample:
www.intel.com/intelpress/usb/examples/DUSBVC.PDF[^]
I have compiled it and confirmed that it works with the 7600.16385.1 DDK. Just paste the code from the Intel PDF file into a Multi-Byte console application created from Visual Studio. You will need to add this #include path to the project:
\7600.16385.1\inc\api
Copy and paste programming at its best.
Best Wishes,
-Copy&Paste
|
|
|
|
|
My project is to make an app that erases media (HDD, USB flash, USB HDD, etc.) showing some information on them. I use \\.\PhysicalDriveX to access the media for details on the size and type (fixed, removable, etc.).
I found that the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Disk\Enum\
keeps up-to-date the drives in order that they are attached.
First it comes the first HDD - subkey "0" something like IDE\DiskWDC_WD5000BEVT-0A0RT0__________________01.01A01\5&2c0d176e&0&0.0.0 , next, the next HDD ... .
Then follows the USB devices, in the order that they were attached.
Here comes trouble...
Consider you have 1 HDD and 2 USB devices A and B.
Subkey 0 holds data for the HDD.
Attach A, subkey 1 holds data for A.
Attach B, subkey 2 holds data for B.
Detach A, subkey 1 holds data for B.
Attach A, subkey 2 holds data for A.
... and all this time ...
A remained \\.\PhysicalDrive1
B remained \\.\PhysicalDrive2
I can`t count on registry for that information, so I have to obtain them - via DeviceIoControl with a handle for \\.\PhysicalDriveX so I can map the devices to the description, exactly.
I hope that is clear enough, now, what is my problem.
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hi,
Could you be a little more clear about the exact problem you are having? While I do understand the problem you mention in your last post... I fail to see how this relates to the original post where you stated that you need 'manufacturer, type, revision'
Someone asked me a similar question a few years ago. Maybe you will find something useful there. Here is the post[^].
If you need to know which physical drive such as \\.\PhysicalDrive1 then you should investigate the IOCTL_STORAGE_GET_DEVICE_NUMBER control code[^] and populate a STORAGE_DEVICE_NUMBER structure[^].
If you are having problems identifying the USB device after the user has moved the USB device... maybe you should investigate the IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER control code[^] and populate a MEDIA_SERIAL_NUMBER_DATA structure[^].
All of this info combined with the Intel sample should give you enough to uniquely identifying drives.
Best Wishes,
-David Delaune
|
|
|
|
|
In this App I use DeviceIoControl to accomplish the following tasks:
- enumerate the PhysicalDriveX devices
- determine nr. of bytes to be overwritten
- for ATA devices determine the Vendor, Product and Revision http://www.winsim.com/diskid32/diskid32.html[^] [http://www.winsim.com/diskid32/diskid32.html[^]] for the reason that the user not to erase a drive that is not intended to.
And all this via a HANDLE from CreateFile("\\\\.\\PhysicalDriveX", ...)
Everything goes OK for ATA , not for USB . In my previous post I have shown an example on how you can`t rely on
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Disk\Enum\N because USB devices are presented in the order they were attached.
So, the question is: can I obtain with a HANDLE created by
CreateFile("\\\\.\\PhysicalDriveX", ...)
data reffering to manufacturer, type, revision for a USB attached storage device?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|