|
|
Up |
|
|
  |
Author: CBFalconerCBFalconer
Date: Nov 30, 2007 23:50
Friedrich Dominicus wrote:
>> How do I sort an string array using pointers
>
> Tip: qsort + strcmp
>
> Have a nice day of C programming
Simpler: Make a singly linked list and apply merge sort.
--
Chuck F (cbfalconer at maineline dot net)
< http://cbfalconer.home.att.net>
Try the download section.
|
| |
|
| |
17 Comments |
|
  |
Author: santoshsantosh
Date: Nov 30, 2007 23:24
> Thanks to everyone on this forum for their helpful comments, now here
> is my solution to Exercise 1.17, pretty short and neat!
>
>
> // print lines longer than 80 chars
>
> char x[160]; // allocate buffer
>
> void main()
Use int main(void)
> {
> while(! feof(stdin)) {
Test with feof() *after* a read operation returns EOF. That's the way it
must be done in C, whether it's intuitive or not.
> gets((char *) &x);
*Never* use gets(). fgets() is almost as easy to use. Also note that the
array name 'x', by itself decays to a pointer to the start of the array
under most conditions. So '&x' is unnecessary, as in the cast.
|
| Show full article (1.09Kb) |
|
| |
8 Comments |
|
  |
Author: erfanerfan
Date: Nov 30, 2007 23:21
On 12月1日, 下午4时07分, Friedrich Dominicus
solutions.de> wrote:
>> How do I sort an string array using pointers
>
> Tip: qsort + strcmp
>
> Have a nice day of C programming
> Friedrich
>
> --
> Please remove just-for-news- to reply via e-mail.
|
| |
|
no comments
|
|
  |
|
|
  |
Author: Keith ThompsonKeith Thompson
Date: Nov 30, 2007 19:16
> On Nov 26, 8:24 pm, "copx" wrote:
>> C's enum type disappoints me a lot.
>>
>> You cannot define which type of integer variable is used. This contradicts
>> C's low level spirit. "I want a number variable. I do not care about size or
>> execution speed." feels like typical ultra high level scripting language
>> design. The compiler could not optimize an enum if it wanted to, because you
>> cannot even specify whether memory requirements or speed are your primary
>> concern. Enums were meant to replace these endless lists of defines you find
>> all over older C source:
>> #define FOO 0
>> #define BAR 1
>> ..
>> It is a technique commonly used to give index numbers meaningful names.
>> However, the variables which hold such numbers often do not need to be wider
>> than one byte and are used a lot. In one program I had many enum-type
>> variables as parts of my data structures and the amount of wasted RAM was
>> excessive when I used C enums, because the compiler (GCC) always used
>> (unsigned) ints, even if the entire range of valid values fitted into a ...
|
| Show full article (1.88Kb) |
|
2 Comments |
|
  |
Author: Tor RustadTor Rustad
Date: Nov 30, 2007 14:33
emre esirik(hacettepe computer science and engineering) wrote:
[...]
> buffer_char3 = strtok (buffer[4], bracket);
> buffer_char3 = strtok (NULL, bracket);
>
> how can I convert buffer_char3 to active.model ( model is char
> array of guitar struct component)
>
> I have tried to find for 4 days, I did everything but I couldnt
> help me please
Posting a minimal self-contained example, demonstrating the "problem",
will generate more useful help.
My guess is, you should look into how strtok() works.
--
Tor
|
| |
|
no comments
|
|
  |
Author: rajashrajash
Date: Nov 30, 2007 13:54
Hi I am new to this forum.
I have taken a class in C some time ago but now I am reading Kernigan
and Richie's book to refresh my knowledge. I think I have forgotten
alot and there are no solutions to the exercises. Maybe some people
here can check through some of my solutions.
Below is a solution to the exercise 1.8.
/* blank counter */
int x, y, z;
void main()
{
char c;
|
| Show full article (0.68Kb) |
|
11 Comments |
|
  |
Author: Martin AmbuhlMartin Ambuhl
Date: Nov 30, 2007 13:21
emre esirik(hacettepe computer science and engineering) wrote:
> struct guitar active;
> char *buffer_char3;
> while(!feof(ptdata))
^^^^^^^^^^^^
This is almost certainly _not_ what you want. Why is this
Pascalism so common? It can't be that any competent C textbook actually
suggests it.
> {
> fgets(buffer[0],26, ptdata);
> fgets(buffer[1],26, ptdata);
> fgets(buffer[2],26, ptdata);
> fgets(buffer[3],26, ptdata);
> fgets(buffer[4],26, ptdata);
Each of the above should be checked for success.
You don't show a declaration of buffer, so I assume it is an
array of char arrays, each of adequate length. Check to make sure.
|
| Show full article (2.03Kb) |
|
no comments
|
|
  |
Author: greggorob64greggorob64
Date: Nov 30, 2007 13:20
Hello, I am working with a system developed several years ago, and was
recently internationalized to support unicode languages.
I am running into a very frustrating and challenging problem:
In 99%% of the textboxes, entering chinese (or japanese or arabic)
characters (using windows IME), in any amount and length, will show
up and puts random characters int he textbox (sometimes '?', sometimes
a box, sometimes a different chinese char, never the correct
character). Spanish, German, etc, sho up fine.
For me to reproduce the symptom, i click inside the textbox, with IME
in chinese, type X, I, enter, enter (to pridoce the xi character, then
a second enter to return out of the ime. eveyrhting shows up properly
until the last enter, when the random garbage is produced.
To further complicate the situation, if i type the test in any other
textbox (word, excel, firefox), the characters show up fine. When i
copy those, and paste into my suspect textboxes, they show up FINE.
|
| Show full article (1.65Kb) |
|
no comments
|
|
  |
|
|
  |
Author: CJCJ
Date: Nov 30, 2007 11:34
Hello friends,
It seems to be quite common in libraries (e.g. GMP) to have typedefs
like
typedef struct {
/* stuff */
} __type_struct;
typedef __type_struct type_t[1];
I guess the advantage of this is that it allows type_t variables to be
passed by reference without an extra level of indirection.
Is this considered good C style? Are there any problems or pitfalls to
be wary of with this approach?
|
| |
|
no comments
|
|
|
|
|
|
|