|
Read my article on extending iostreams to write a custom stream. I'd impliment a stream that derives from fstream, and add behaviour to count newlines and stop on a ;
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
This may be of some help.
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] = "This is a sample string";
char key[] = "aeiou";
char * pch;
printf ("Vowels in '%s': ",str);
pch = strpbrk (str, key);
while (pch != NULL)
{
printf ("%c " , *pch);
pch = strpbrk (pch+1,key);
}
printf ("\n");
return 0;
}
Output:
Vowels in 'This is a sample string': i i a a e i
Thank You
Bo Hunter
|
|
|
|
|
Hey, cool. A C programmer. Is there much work in C still ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
How would you go about developing an algorithm that would for
example takes a list of songs and shuffles them and uses each
song once and only once? Also what if you wanted to me aware
of the order so that you could have a previous function that
would give you the previous song in the list back to the
beginning?
Thanks,
Steve
|
|
|
|
|
This is not optimal, but it can serve your purposes:- Let
n be the number of songs to shuffle.
- Define a map of
int s to string s.
- For every song in the list:
- Generate a random number
r between 0 and n-1 , check if the r -th entry of the map is empty, repeat until you find an empty slot.
- Insert the song into the map using index
r
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for your responses. I will look into Mr. Dunn's comment as well.
Steve
|
|
|
|
|
I recommend you rather follow Mr Dunn's comment, it is a much cleaner solution. Somehow I forgot about std::random_shuffle .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
I recommend you rather follow Mr Dunn's comment, it is a much cleaner solution. Somehow I forgot about std::random_shuffle.
Muchas gracias tio.
Steve
|
|
|
|
|
|
Has anybody been able to build the Boost library for MS Visual C++ 6.0. I have downloaded Boostjam and followed all the instructions on getting the library built but I don't get any *.lib files in the end, just .CMD files.
Can anybody help?
I am the handsome one in the crowd.
|
|
|
|
|
I guess you might get more helpful response at the Boost Users mailing list[^].
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I have been drawing a dialog box with CDC class. How do I clear what I have drawn to the dialog box?
|
|
|
|
|
With RedrawWindow maybe?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I reposting this in the vain hope of a new reply:
How do you specify to use the deprecated fstream rather than the std::fstream ? I am encountering major proplems with this, and it seems there is no easy solution listed, and it seems that there should be.
J.
----------------------------
|
|
|
|
|
old fstream is included by (deprecated) <fstream.h> , but if you're mixing old and new C++ you sure are going to run into trouble.
Cannot you afford upgrading to std::fstream instead? If you have problems in the process, here we are to provide a little help
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I am trying to include some source with STL into a project that uses lots of plain vanilla fstreams. It is not really practical to go through and change the old code because of the enormity of the task. I have tried using blank namespace to no avail, but perhaps I am doing something wrong.
J.
----------------------------
|
|
|
|
|
Could you please explain what yout "blank namespace" trick consists in?
Anyway, doesn't your program work if you include <fstream.h> ?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I have used <fstream.h> but one of the alterations was in the stdafx.h file which then in turn seems to confuse the compiler and it seems to be misdirected so that it can't find the correct headers. I get a huge number of errors after that all having to do with the fstream functions. I started to change the <fstream.h> to the templated <fstream> but then discovered that this in turn would require more changes because the geniuses at C++ standards committee had changed some member functions there too.
I have had similar problems on linux GCC in which updated compilers seem to break when trying to compile code that was compiling perfectly beforehand. fstream again seems to be the class that confuses it.
J.
----------------------------
|
|
|
|
|
Blank namespace is just one of things I was trying - something outside of std. In relation to the code that worked perfectly before std, std is now broken. It follows a different, supposedly outdated standard. I am just looking for some directive that will force it to use the old pre-namespace headers and libraries for a given file or global scope.
J.
----------------------------
|
|
|
|
|
How can I access the raw tcp packet? Any help is appreciated.
Thank you.
mweiss
|
|
|
|
|
Hi,
(I am a rookie, but trying to learn, very interested in everything. Now using Borland vc++ and M$ vc++.)
To keep it simple: I want to make a calendar with scheduled events.
I've been searching for the best ways to do this, but I still don't know what's the best way.
Simplest way is to make a timer-function that runs every minute so that a trigger-file(with the events(date/time/event) ) can be checked. This seems not a good option?
(I don't want to read/write/use the Task Scheduler in Windows.)
Any suggestions?
Thx in advance, Roland(Be).
|
|
|
|
|
Maybe I can run a function that sorts the triggers by time (sort of queue) and then just wait for the first timed event with sleep()...(?) where the function can be started again and removes the (first) event from queue(/file)?
It's a way to not-use the timer-function every minute...
|
|
|
|
|
I'd go for the one minute timer approach. The other solution is more elegant, so to say, but:- The load of the one minute timer is negligible,
- if next event happens in two hours, and the user inserts a new event popping out in an hour, what would you do (with the second approach)? Kill the timer and reset it? Things begin to get complicated.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hmm,
I think I'll do it like this;
1.
EVENT = Name of Event + Date/time + ...extra info(like recurring, etc.)
2.
If(EVENT change/new/del)<br />
{<br />
function(queue)-> This wil sort the queue with events and pick out the 1st that's upcomming to put this in memory/file.<br />
}
3.
Timer every minute-> That reads only the upcomming event. (this way the program also doesn't run function(queue) every minute.)
4.
Output...
And of course when program starts run function(queue) in case of bad data(ie. crash/powercut/etc)
|
|
|
|
|