I have a project (C language) where I implement multiple operations over a spreadsheet, that looks like this (and will be given in a .txt file):

Operations that I have to implement will be, for example, to delete specific row, add new column, change value of cell and so on...

Thanks for any help. ]]>

Code:

`struct date{ int day, month, year;`

};

struct detail{

float quantity;

struct date expdate;

};

struct item{

int itemID;

char name[20], measure[10], lowestamt[10], status[10];

struct detail q[10];

};

struct item Ingredient;

Code:

`void bubbleSort(int myArray[]);`

int main(){

FILE *fptr;

char ptr[1000] = "numbers.txt";

int myArray[500];

int i;

fptr = fopen(ptr,"r");

if (fptr == NULL){

printf("Error Reading File\n");

exit(0);

}

for (i = 0; i < 7; i++){

fscanf(fptr, "%d,", &myArray[i]);

}

for (i = 0; i < 7; i++){

printf("Number: %d\n", myArray[i]);

}

printf("\n");

bubbleSort(myArray);

for (i = 0; i < 7; i++){

printf("Sorted numbers: %d\n", myArray[i]);

fptr = fopen(ptr,"w");

}

fclose(fptr);

return 0;

}

void bubbleSort(int myArray[]){

int i, j, temp;

for(i = 0; i < 7 - 1; i++){

for(j = 0; j < 7 - 1; j++){

if (myArray[j] > myArray[j+1]){

temp = myArray[j];

myArray[j] = myArray[j+1];

myArray[j+1] = temp;

}

}

}

}

i have to program i work calculator which prompts the user for the days and then ask how many hours the person worked a day.

the expected output is:

The program calculates the total hours worked during

a specific period and the average length of a day.

How many days: for example i put 3

Enter the working hours for day 1: x

Enter the working hours for day 2: x

Enter the working hours for day 3: x

Total hours worked: xx.x

Average length of day: x.x

Hours entered: x.x x.x x.x

theres also a hint:It is easiest to implement the program using an array with 30 elements.

what does it mean? array to what?, im new to arrays and cant find any help or examples with that kind of program, even though i understand how arrays work. i dont get what does that mean. do i have to link for example dailyhoursday[0] to 6.6 hrs and dailyhoursday[1] to 8.6 etc?

thanks for help ]]>

I believe that this is very simple but I cannot figure out why the following bitwise operation do not work

Code:

// Get the unique identifier of the device

uint32_t msb;

uint32_t lsb;

lsb = NRF_FICR->DEVICEID[0]; // read the less significant 32bits

msb = NRF_FICR->DEVICEID[1]; // read the most significant 32bits

uint64_t deviceID = (uint64_t)msb << 32 || lsb; // 64 bit unique device identifier

NRF_LOG_INFO("lsb: %x", lsb);

NRF_LOG_INFO("msb: %x", msb);

NRF_LOG_INFO("Device ID: %x", deviceID);

Any advice?

Nick

In MSVC 2019 16.7.4 the following code manage to compile but not in CLANG

Code:

` if (lpOverlapped)`

{

bResult = (lpOverlapped->dwCommand == FILE_READ ? ReadFile : WriteFile)(

lpOverlapped->hFile->FileHandle,

lpOverlapped->lpBuffer, lpOverlapped->dwBuffer, &dwResult, (LPOVERLAPPED)lpOverlapped);

if (! bResult && (dwResult = GetLastError()) != ERROR_IO_PENDING)

{

lpOverlapped->Internal = dwResult;

PostQueuedCompletionStatus(hCompletionPort, 0, (DWORD)-5, (LPOVERLAPPED)lpOverlapped);

}

}

Quote:

error : called object type 'void *' is not a function or function pointer

Code:

`bResult = (lpOverlapped->dwCommand == FILE_READ ? ReadFile : WriteFile)(`

It been a really long time ive spent time on this board and ive moved on from C and im trying to get back into it. However my memory had been very rusty.

Could someone please help understand why i get 3 3 1 here please?

Code:

`#include <stdio.h>`

int main ( int argc, char *argv[] ) {

int x = 1;

printf ( "%d %d %d\n", ++x, x, x++ );

return 0;

}

Many thanks ]]>

Code:

`int main()`

{

int n = 0;

int guess=0;

char answer[14];

srand(time(0));

do {

guess = rand();

printf("actual is %d ", guess);

printf("Input a number: ");

fgets(answer,20,stdin);

printf("actual is %d ", guess);

n = atoi(answer);

printf("");

printf("guess is %d", n);

if(n == guess) {

break;

}

printf("Incorrect! Guess again (y/n)? ");

fgets(answer,4,stdin);

}

while(answer[0] == 'y');

return 0;

}

Each triangle is described by a triangle_t data structure. All the functions below accept a pointer to a triangle data structure as input. Each function needs to access and modify the fields of the data structure as appropriate.

Note that triangle scale is specified as a floating-point number, while the triangle coordinates are integer variables. You will need to think about conversions between integer and floating-point numbers to make the scaling function work properly. When scaling, translation, and drawing works, embark on the code for filling the triangles.

i managed to go this far, but still no tea pot appear on my screen, i think i am doing something wrong can you help me please , i think there is something to with triangle scale is specified as a floating-point number, while the triangle coordinates are integer variables. here what i worte so far :

Code:

Code:

`#include<stdlib.h>`

#include<stdio.h>

#include<SDL.h>

#include"triangle.h"

#include"drawline.h"

#defineTRIANGLE_PENCOLOR0xBBBB0000

/*

* Print triangle coordinates along with a message

*/

void print_triangle(triangle_t *triangle, char *msg)

{

printf("%s: %d,%d - %d,%d - %d,%d\n",

msg,

triangle->x1, triangle->y1,

triangle->x2, triangle->y2,

triangle->x3, triangle->y3);

}

/*

* Return 0 if triangle coordinates are outside the surface boundary. 1 otherwise.

*/

int sanity_check_triangle(SDL_Surface *surface, triangle_t *triangle)

{

if (triangle->sx1 < 0 || triangle->sx1 >= surface->w ||

triangle->sx2 < 0 || triangle->sx2 >= surface->w ||

triangle->sx3 < 0 || triangle->sx3 >= surface->w ||

triangle->sy1 < 0 || triangle->sy1 >= surface->h ||

triangle->sy2 < 0 || triangle->sy2 >= surface->h ||

triangle->sy3 < 0 || triangle->sy3 >= surface->h) {

return 0;

} else {

return 1;

}

}

/*

* Scale triangle, altering the on-screen coordinates(e.g. triangle->sx1)

*/

void scale_triangle(triangle_t *triangle)

{

// TODO: Replace the code below with code that scales each triangle coordinate.

// The scaling factor is specified in triangle->scale.

// Remember that this function MUST write to the on-surface coordinates.

// Do not alter the model coordinates.

float dx1=0, dx2=0, dx3=0;

float dy1=0, dy2=0, dy3=0;

triangle->sx1 = triangle->x1;

triangle->sx2 = triangle->x2;

triangle->sx3 = triangle->x3;

triangle->sy1 = triangle->y2;

triangle->sy2 = triangle->y1;

triangle->sy3 = triangle->y3;

dx1=((triangle->x2-triangle->x1)*triangle->scale);

dx2=((triangle->x3-triangle->x2)*triangle->scale);

dx3= ((triangle->x1-triangle->x3)*triangle->scale);

dy1=((triangle->y2-triangle->y1)*triangle->scale);

dy2= ((triangle->y3-triangle->y2)*triangle->scale);

dy3= ((triangle->y1-triangle->y3)*triangle->scale);

triangle->sx1= triangle->sx3+dx3;

triangle->sx2= triangle->sx1+dx1;

triangle->sx3=triangle->sx2+dx2;

triangle->sy1= triangle->sy3+dy3;

triangle->sy2= triangle->sy1+dy1;

triangle->sy3=triangle->sy2+dy2;

}

/*

* Move the triangle to the center of the surface,

* altering the on-screen coordinates(e.g. triangle->sx1)

*/

void translate_triangle(triangle_t *triangle)

{

// TODO: Insert code that moves the triangle on the surface.

// The translation coordinates are specified in triangle->tx and triangle->ty.

// Remember to use the on-surface coordinates (triangle->sx1, etc.)

triangle->tx = 1024/2;

triangle->ty = 768/2;

triangle->sx1=(triangle->tx+triangle->sx1);

triangle->sx2 = (triangle->tx+triangle->sx2);

triangle->sx3 =(triangle->tx+triangle->sx3);

triangle->sy1 = (triangle->ty+triangle->sy1);

triangle->sy2= (triangle->ty+triangle->sy2);

triangle->sy3 = (triangle->ty+triangle->sy3);

}

/*

* Calculate the triangle bounding box,

* altering fields of the triangle's rect(e.g. triangle->rect.x)

*/

void calculate_triangle_bounding_box(triangle_t *triangle)

{

// TODO: Insert code that calculates the bounding box of a triangle.

// Remember to use the on-surface coordinates (triangle->sx1, etc.)

// The bounding box coordinates should be written to

// triangle->rect.x, triangle->rect.y, triangle->rect.w, triangle->rect.h

triangle->rect.w = triangle->rect.w - triangle->rect.x;

triangle->rect.y = triangle->rect.y - triangle->rect.h;

// Calculate max value for x

triangle->rect.w = triangle->sx1;

if (triangle->sx2 > triangle->rect.w)

{

triangle->rect.w = triangle->sx2;

}

if (triangle->sx3 > triangle->rect.w)

{

triangle->rect.w = triangle->sx3;

}

// Calculate min value for x

triangle->rect.x = triangle->sx1;

if (triangle->sx2 < triangle->rect.x)

{

triangle->rect.x = triangle->sx2;

}

if (triangle->sx3 < triangle->rect.x)

{

triangle->rect.x = triangle->sx3;

}

// Calculate max value for y

triangle->rect.y = triangle->sy1;

if (triangle->sy2 > triangle->rect.y)

{

triangle->rect.y = triangle->sy2;

}

if (triangle->sy3 > triangle->rect.y)

{

triangle->rect.y = triangle->sy3;

}

// Calculate min value for y

triangle->rect.h = triangle->sy1;

if (triangle->sy2 < triangle->rect.h)

{

triangle->rect.h = triangle->sy2;

}

if (triangle->sy3 < triangle->rect.h)

{

triangle->rect.h = triangle->sy3;

}

}

/*

* Fill the triangle on the surface with the triangle's color

*/

void fill_triangle(SDL_Surface *surface, triangle_t *triangle)

{

// TODO: Insert code that fills the triangle with the color specified in triangle->fillcolor.

// Hint: Draw the triangle with color TRIANGLE_PENCOLOR (this color can not

// occur in e.g. the teapot or the example triangles). Thus, if your

// approach to filling the triangle relies on looking for the edges of

// the triangle on the surface (via the GetPixel function), you will find those

// edges even if the triangle overlaps with a triangle that has already

// been drawn on the surface.

int i, j, k;

for (k = triangle->rect.h; k <= triangle->rect.h; k++)

{

for(i = triangle->rect.x; i <= triangle->rect.w; i++)

if (get_pixel(surface, i, k) == TRIANGLE_PENCOLOR)

{

break;

}

for (j = triangle->rect.y; j <= triangle->rect.h; j++)

if (get_pixel(surface, j, k) == TRIANGLE_PENCOLOR)

{

break;

}

draw_line(surface, i, k, j, k, triangle->fillcolor);

}

}

/*

* Draw a filled triangle on the given surface

*/

void draw_triangle(SDL_Surface *surface, triangle_t *triangle)

{

int isOK;

/* Scale. */

scale_triangle(triangle);

/* Translate. */

translate_triangle(triangle);

/* Determine bounding box */

calculate_triangle_bounding_box(triangle);

/* Sanity check that triangle is within surface boundaries. */

isOK = sanity_check_triangle(surface, triangle);

if (!isOK) {

print_triangle(triangle, "Triangle outside surface boundaries");

return;

}

/*

* TODO: Insert calls to draw_line to draw the triangle.

* Remember to use the on-surface coordinates (triangle->sx1, etc.)

*/

draw_line(surface, triangle->sx1, triangle->sy1, triangle->sx2, triangle->sy2, TRIANGLE_PENCOLOR);

draw_line(surface, triangle->sx2, triangle->sy2, triangle->sx3, triangle->sy3, TRIANGLE_PENCOLOR);

draw_line(surface, triangle->sx3, triangle->sy3, triangle->sx1, triangle->sy1, TRIANGLE_PENCOLOR);

/* Fill triangle */

fill_triangle(surface, triangle);

}

]]>

Code:

`#include <stdio.h>`

#include <stdlib.h>

#define N 5

int main()

{

int counter = 0, num = 0;

int memory[N];

while(scanf("%d", &num) != EOF){

if (counter == N){

for(int i = 0; i< N-1; i++){

memory[i] = memory[i+1];

}

memory[N-1] = num;

continue;

}

memory[counter] = num;

counter++;

}

for(int i = 0;i < counter; i++){

printf("%d ", memory[i]);

}

return 0;

}

My while loop wouldn't terminate when I enter -1 as value, it just keeps registering more and more numbers into the array even the -1 and never reaches the second part of the code(the printf).

the only solution I could think of is adding another if statement but I feel like it's supposed to be working without it.

Code:

`#include <stdio.h>`

#include <stdlib.h>

#define N 5

int main()

{

int counter = 0, num = 0;

int memory[N];

while(scanf("%d", &num) != EOF){

if(num == EOF){

break;

}

if (counter == N){

for(int i = 0; i< N-1; i++){

memory[i] = memory[i+1];

}

memory[N-1] = num;

continue;

}

memory[counter] = num;

counter++;

}

for(int i = 0;i < counter; i++){

printf("%d ", memory[i]);

}

return 0;

}

If it's not supposed to be working without the second if statement may I recieve a small explanation to why it is like this?

Thanks alot in advance! ]]>

Code:

`#include <stdio.h>`

#include <stdlib.h>

#include <assert.h>

#include <stdbool.h>

bool sorted_asc(void *data, size_t size, size_t datasize,

int (*compare)(const void *a, const void* b))

{

unsigned char *p = data;

for (int i = 0; i < size - 1 ; i++)

{

if(compare(p + i * datasize, p + ((i + 1) * datasize)) > 0)

return false;

}

return true;

}

bool sorted_desc(void *data, size_t size, size_t datasize,

int (*compare)(const void *a, const void* b))

{

unsigned char *p = data;

for (int i = 0; i < size - 1 ; i++)

{

if(compare(p + i * datasize, p + ((i + 1) * datasize)) < 0)

return false;

}

return true;

}

/* sorted - check if an array is sorted - either in descending or

* ascending order

*

* Possible use:

* assert(sorted(...));

* qsort(...)

* or

* assert(!sorted(...))

* qsort(...)

*/

bool sorted(void *data, size_t size, size_t datasize,

int (*compare)(const void *a, const void* b))

{

return sorted_asc(data, size, datasize, compare) ||

sorted_desc(data, size, datasize, compare);

}

int compare_int(const void *a, const void *b)

{

const int *i1 = a;

const int *i2 = b;

return *i1 - *i2;

}

int main(int argc, char **argv)

{

int a1[] = {1,2,3,4,5};

int a2[] = {5,4,3,2,1};

int a3[] = {3,2,1,4,5};

assert(sorted_asc(a1, 5, sizeof(int), compare_int));

assert(sorted_desc(a2, 5, sizeof(int), compare_int));

assert(!sorted(a3, 5, sizeof(int), compare_int));

assert(sorted(a1, 5, sizeof(int), compare_int));

assert(sorted(a2, 5, sizeof(int), compare_int));

printf("ALL TESTS PASSED\n");

return EXIT_SUCCESS;

}

Code:

`#include int main()`

{

float f = 0.1;

fwrite(&f, sizeof f, 1, stdout);

return 0;

}

here is my function:

Code:

`char *cat(char *dest, char *src)`

{

int j = strl(dest);

int i;

i = 0;

while (src[i])

{

dest[i + j] = src[i];

i++;

}

dest[i + j] = 0;

return (dest + i +j);

}

We paste the source at the first \0 of dest and then (this is were the problems start) we return the end of the pasted source so that we can keep on concatenating string.

for some reason if I do a printf of the returned string inside the function everything is fine but if I try to printf it outside the function I get a seg fault.

If you have any idea on what is wrong or can show me the way you solved this problem, please let me know.

Any help is very much appriciated, thanks for your time. ]]>

I settled on Qt because it is portable, well supported, has great documentation, I'm already using it (KDE) and will serve me as an excuse to start learning C++.

I was wondering what would be the best way to integrate the GUI into my existing program. Should I change my program into a library and link it into the GUI. Should I keep the CLI part? I'd like to but how difficult would it be to integrate.

I'm thinking the easiest way, specially considering the crosscompilation (I'm assuming Qt has a very complicated, unique way to do this) would be to compile my existing program as a library, exposing only certain general functions to communicate with the GUI which would collect and validate input, and produce feedback. I can simply gather input on the GUI code, pass it to a "collector" function that will populate my program's structures and validate the input.

This would be a very runabout way to do it though, and I'd be wasting opportunities to take advantage of the GUI to streamline my code. ]]>

Here is my code:

Code:

`void deleteFunc(struct Array *myArr, int x ){`

int i, size;

if(myArr -> length == 0)

{

printf("Value not found is in Array \n\n");

return ;

}

if(x >= 0 && x < myArr -> length){

for(i = x; i < myArr -> length -1; i++){

myArr -> A[i] = myArr -> A[i+1];

}

myArr -> length--;

printf("Array before deletion: ");

for(i = 0; i < size; i++){

printf("%d", myArr[i]);

}

printf("Array after deletion: ");

for(i = 0; i < size; i++){

printf("%d", myArr[i]);

}

}

or reload the browserDisable in this text fieldEditEdit in GingerEdit in Ginger×Enable Ginger

or reload the browserDisable in this text fieldEditEdit in GingerEdit in Ginger×Enable Ginger

or reload the browserDisable in this text fieldEditEdit in GingerEdit in Ginger×Enable Ginger

or reload the browserDisable in this text fieldEditEdit in GingerEdit in Ginger×Enable Ginger

or reload the browserDisable in this text fieldEditEdit in GingerEdit in Ginger× ]]>