NO

Recent Posts

Pages: [1] 2 3 ... 10
1
Beginner questions / Re: Array do not have the correct Elements ?
« Last post by John1 on Yesterday at 10:15:15 pm »
I changed it following the first two advises.

Quote
3. use tempory buffer for input and malloc only needed memory and copy that string to it.
Sorry I couldn´t understand the third advise ?

Actually it puts still the wrong Elements in the Array. Input: Car one - Car two - Car three

Code: [Select]
void addNewCar(void) {
 car = (char*)malloc(100*sizeof(char));
 printf("Add new Car : ");
 if(fgets(car,100,stdin) == NULL) {
  printf("Wrong Input\n");
  dump_buffer(stdin);
  free(car);
  return;
 }
 carA[z++] = car;
 return;
}

Output :

Element : Car one and  Index : 0
Rented Car : Car one

Element : Car three and  Index : 1
Rented Car  : Car three

Element : Car three and  Index : 2
Rented Car : Car three
2
Beginner questions / Re: Array do not have the correct Elements ?
« Last post by TimoVJL on Yesterday at 06:28:35 pm »
couple things:
1. use if (fgets(car, 100, stdin) == NULL) as sizeof(car) is a pointer size.
2. don't free memory in addNewCar(), do it end of program
3. use tempory buffer for input and malloc only needed memory and copy that string to it.
3
Beginner questions / Re: Array do not have the correct Elements ?
« Last post by John1 on Yesterday at 05:31:44 pm »
Hello TimoVJL,

Thank you for your answer.

I use char* carA[100]; to declare the Array.
I changed i <= (int)strlen(*carA)-1;  to i < z; .

I tried a bit to change my Code similar to your Example, but I couldn´t let it run, due an Exception 255. To not copy and paste your Code and learn something.

Here is the Code I use to add Elements to the Array, maybe you may see some Errors.

Code: [Select]
void addNewCar(void) {
 char* car = (char*)malloc(100*sizeof(char));
 printf("Add a new Car : ");
 if(fgets(car,sizeof(car),stdin) == NULL) {
  printf("Wrong Input\n");
  dump_buffer(stdin);
  free(car);
  return;
 }
 carA[z++] = car;
 free(car);
 return;
}
4
Beginner questions / Re: Array do not have the correct Elements ?
« Last post by TimoVJL on Yesterday at 02:05:56 pm »
Your array structure is unknown, so hard find errors, and this is weird for me:
Code: [Select]
i <= (int)strlen(*carA)-1;the lenght of the first string array element - one ?

an example with a static string array
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int __cdecl main(void)
{
char buf[80], astr[10][100]; // an array of strings
int cnt = 0; // string counter
while(fgets(buf,sizeof(buf),stdin)) { // read to buffer, not really needed with a static string array
if (*buf == 10 || cnt >= 10) break; // exit if plain ENTER or array limit
int len = strlen(buf);
buf[len-1] = 0; // remove LF
strcpy(astr[cnt], buf); // copy to array
cnt++; // advance next
}
for (int i=0; i<cnt; i++)
printf("%d %s\n", i, astr[i]);
return 0;
}
5
Beginner questions / Array do not have the correct Elements ?
« Last post by John1 on December 17, 2018, 10:43:19 pm »
Hello,

I´m quite new to C and try to learn. After some time of trying different codes, I decided to post here. Among various Problems in the Program, I will start with one. Sorry for my english.

The Program gets the input from fgets fgets(car,sizeof(car),stdin) and give the value to an Array char* carA[100]; with carA[z++] = car; .

Strange is that the Index is incrementing, but the Values at the Output are not correct :

Code: [Select]
void listCars(void) {
          for(int i = 0; i <= (int)strlen(*carA)-1; i++) {
  printf("Cars rented : %s\n", carA[i]);
 }
}

6
Expert questions / Re: Computed goto?
« Last post by TimoVJL on December 17, 2018, 07:33:54 pm »
7
Expert questions / Re: Computed goto?
« Last post by frankie on December 17, 2018, 05:29:12 pm »
"Labels as values" are a C language extension indeed, AFAIK also supported by clang, perhaps other compilers as well.
"Labels as values" is a custom extension introduced by gnu compiler, eventually adopted by LLVM (see) and maybe someone else.
It is definitely not a C language standard feature.
8
Expert questions / Re: Computed goto?
« Last post by Akko on December 17, 2018, 01:12:09 pm »
This is a GCC extension, and is not part of C standard.
PellesC doesn't implement this extension.
To create jump tables you must use standard switch statement.

"Labels as values" are a C language extension indeed, AFAIK also supported by clang, perhaps other compilers as well.

The most prominent usage of label as value is in interpreters for threaded code.

The labels within the interpreter function can be stored in the threaded code for super-fast dispatching,
a popular method for building virtual machines.

10
Add-ins / Re: PrjObjDmpZds Add-In using Zydis.dll
« Last post by TimoVJL on December 15, 2018, 09:59:37 am »
Using Zydis version 3
Pages: [1] 2 3 ... 10