## c99 – Take an input list remove all duplicates and count how many they are

Hi, I have tried to do this function but sometimes I have a runtime problem. I need to enter a list like 1-2-3-2-4-6-1-2 and the list has to be changed to 1-2-3-4-6 so once for each node and I have to record how several times a node is repeated, for example 1 is repeated 2 times, the 2 is repeated 3 times, etc.

``````node *modify(node *head){

int counter, pass, m;

node *curr = head;
node *track = head;

while (track->next != NULL){
counter = 0;
pass = 0;
m = track->val;
while((curr)->next != NULL){
if(m == (curr)->val){
pass++;
counter++;
if(pass > 1){
node *removed = curr;
curr = (curr)->next;
free(removed);
}
if(pass == 1)
curr = curr->next;
}
else{
curr = (curr)->next;
}
}
track->rip = counter;
track = track->next;
curr = track;
}

}
$$```$$
``````

## c99 – Delete all nodes repeated more than x times

I don't understand why this function returns something bad, it must take as input the head of a list and an integer. This function must delete all the nodes which are repeated> = x times, therefore `1->2->2->2->3->3->4` should just come back `1->4` if x = 2;

``````    node_t *modificaLista(node_t *head, int x){

node_t *curr = head;
node_t *track = head;
int counter = 0;

while (track->next != NULL){
if (track->val == curr->val)
counter++;
curr = curr->next;
if(curr->next == NULL){
if (counter >= x){
curr = track;
while(curr->next != NULL){
if(curr->val == track->val){
node_t *removed = curr;
curr = curr->next;
free(removed);
}
else {
curr = curr->next;
}
}
}
track = track->next;
curr = track;
counter = 0;
}
}

}
$$```$$
``````

## Macros – Solution: The clang preprocessor concatenates an extra space compared to standard gcc – C99

I maintain a C library project on gcc and clang.

I'm looking for advice on how to make the following macros more portable, concise, readable, or standards-compliant.

When I compile

``````#define STRINGIFY(arg) STRINGIFY_(arg)
#define STRINGIFY_(arg) #arg

#define VERSION 1.01
#define PROJECT myProject
#define SUB_PROJECT mySub
#define DASH -

#include STRINGIFY(PROJECT DASH SUB_PROJECT DASH VERSION.c)
``````

Clang 6.0.0 standard C99

``````myProject - mySub - 1.01.c
``````

gcc 7.4.0 standard C99

``````myProject-mySub-1.01.c
``````

I came up with the following solution

``````#define STRINGIFY(arg) STRINGIFY_(arg)
#define STRINGIFY_(arg) #arg
#define ID(arg) arg

#define VERSION 1.01
#define PROJECT myProject
#define LIB myLib
#define DASH -
#define DOTC .c

#define FILEVERSION(a, b, c, d, e) STRINGIFY(ID(a)ID(b)ID(c)ID(d)ID(e)ID(DOTC))

#include FILEVERSION(PROJECT, DASH, LIB, DASH, VERSION)
``````

## c99 – How to initialize a character[] with a string in C?

I have a union of tables of characters, bytes, words and long words that I have to initialize selectively.
I realized that I could not use more than one union member for booting. All arrays must be initialized via the byte array, even if the initial values ​​are 16-bit or 32-bit.
(that is to say instead of

``````array_words(0) = 0x1234
I need to do:
array_bytes(0) = 0x12;
array_bytes(1) = 0x34; // etc
``````

No matter what I try to fail unless I do the following:

``````array_chars(0) = 'H',
array_chars(1) = 'e',
array_chars(2) = 'l', // etc.
``````

The question: Can I somehow initialize a range of characters with a string or sequence of characters like this?

``````array_chars(0 ... 6) = { "Hello" };
``````

or even

``````array_chars(0 ... 6) = { 'H', 'e', 'l', 'l', 'o', '' };
``````

## How to make a pre C ++ wrapper 11 of a POD structure made in C99?

Very good. First, the question may not be in the correct format. I will modify it as I add more information or the comments show a lack of information or structure.

I have a structure made of POD, in C99.

I will give an example of the type of structure in which I usually find the one that interests me (kindly extract Freetype 2.4.4):

``````        typedef enum BDF_PropertyType_
{
BDF_PROPERTY_TYPE_NONE = 0,
BDF_PROPERTY_TYPE_ATOM = 1,
BDF_PROPERTY_TYPE_INTEGER = 2,
BDF_PROPERTY_TYPE_CARDINAL = 3

} BDF_PropertyType;
typedef struct BDF_PropertyRec_
{
Type BDF_PropertyType;
union {
const char * atom;
FT_Int32 integer;
Cardinal FT_UInt32;

} u;

} BDF_PropertyRec;
``````

My question is: How to get a wrapper in C ++ 98 to interconnected structures?

I planned to do a course that used a `BDF_PropertyRec`but using it as a private object and using it, but I still depend on `malloc` and `free` for its life cycle, quickly abandoning the idea by keeping in mind the two objects, as they do here: https://os.mbed.com/questions/241/How-to-wrap-C-functions -into-C -class /

Here, https://stackoverflow.com/a/17454763/8607301, apply a form of the inheritance type to get a wrapper. I do not see how to achieve this with POD structures or classical data that have pointers connected to other structures, or a vector of these elements given by the base pointer and the maximum length, something like this:

``````typedef struct t_Elements_used
{
uint8_t value1;
uint16_t value2;
uint8_t value3;
uint32_t value4;
} * Elements_used; // Look at the pointer element, here it is cheating!

typedef struct t_Structura_POD_con_vectores
{
uint32_t elements;
Vector elements used; // It's cheating, read the definition of the previous typedef well!

} Structure_POD_with_vectors; // <How to integrate this in a class?
``````

In software engineering (https://softwareengineering.stackexchange.com/q/181587/296879), they comment with the help of facades or `std :: make_unique`. In the case of C ++ 98, `std :: make_unique` it does not work (you have to insert the extension TR1 or use boost, and for the moment, it is not viable), and a facade pattern adds too many layers to access the elements of this vector, which makes the difficult encapsulation (one layer for the first structure, another for the second and one for the communication between the two, leaving the original structure duplicated, but I do not see that it is accessible without copies.

As I read in Coding Standards C ++ – 101 Rules, Guidelines and Best Practices, from Herb Sutter and Andrei Alexandrescu, recommends the use of RAII (Recommendation 13), which involves duplicating and to maintain the two objects, the structure and the object. C ++ converted.

I repeat the question: How to create a wrapper in C ++ 98 (obsolete!) For a structure connected to others in C99?