2018-10-22         Harriet

ANSI C: Declare a pointer of type "array of string"

I have a structure like thisstruct { int id; char str00[10]; char str01[10]; char str03[10]; char str04[10]; ...} myStructure;All strXX have the same size. I would like to access them via an array (strArray), like this :strcpy(strArray[i], strValue);How to declare strArray ?I used this:char (*strArray)[][10] = (void *)&myStructure.str00;It's working, but I have to code the strcpy like thisstrcpy((*strArray)[i], strValue);... and I don't like this :-)Is there another way to declare strArray ?Thanks for your ideas and help. You almost had it, the c...

 c                     2 answers                     37 view
 2018-10-22         Darnell

Automatic storage duration struct initialization

Some of this may be a duplicate, but I am sorry for that.Let's say I have this struct:struct foo{ int a; int b; int c;};1. If struct foo type object is declared in the way that it has automatic storage duration and without initializers, is it guaranteed that all it's members will be force initialized to zero?{ // other stuff struct foo bar; // other stuff}2. If struct foo type object is declared in the way that it has automatic storage duration and with some initializers, is it guaranteed that members, which are not explicitly initialized, will be force ...

 c                     2 answers                     61 view
 2018-10-22         Jerry

How do I use clipboard in GTK?

How can I, using GtkClipboard, read and write to a clipboard? As an example, please show me how to get the current clipboard content and print it to console.I tried this to get and print what is currently in the clipboard, but it doesn't work:GtkClipboard *clip = gtk_clipboard_get(GDK_SELECTION_PRIMARY);gtk_clipboard_request_text(clip, (GtkClipboardTextReceivedFunc)print_clip, NULL);Everything compiles without any warnings, but print_clip() function is never reached. Maybe I should use another function, like gtk_clipboard_wait_for_text()? Please help me, what am I supposed ...

 c                     2 answers                     62 view
 2018-10-22         Blithe

how to update table size inside hash function

I was learning how to implement Hash table but i am bit confused here in because in the book below code was available and i understood well enough the code, but inside book there was no definition of HASH function ,i know we have to define it by own ,but according the below code that was given give inside book HASH is taking two arguments wherever i used the HASH like in HashInsert it is taking two arguments index=HASH(data,t->size) if we assume that return type of HASH as int now for eg we can define HASH as int HASH(int data,int tsize){return(data%7);}but according ...

 c                     1 answers                     63 view
 2018-10-22         Merlin

How to fix "error:assignment to expression with array type"?

I'm getting an error: error:assignment to expression with array typein this program, which should print words that have 4-8 letters:#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){ char rec[300]; int zbroj1=0, br=0, zbroj2=0; while((rec=getchar()) != '\n') { zbroj1++; } if(zbroj1>=4 || zbroj1<=8) printf("Nova recenica je: %s", zbroj1); return 0;}How can I fix this? Below is the code to print words of size >= 4 and <= 8#include<stdio.h>int main(void) { char rec[9]; //you may need to adjust the ...

 c                     4 answers                     64 view
 2018-10-22         Bernie

Relocation compiling issue with shared flags

I have a program in C that uses the GSL to integrate an ODE system, and store the resulting data in arrays. The code is at the end of the question, but as you'll see it's not really the issue here. Secondary to the C code, I use a Python script to pass the array pointers into the C code using ctypes, since I later want to plot and manipulate the array data. All of which is fine, it worked with small test programs. But to do so, I need to create a shared library using gcc. Here's where things go wrong. When I compile with gcc ctest.c -o ctest.o -std=c11 -Wall -g -lgsl -...

 c                     1 answers                     65 view
 2018-10-22         Bridget

__attribute__((constructor)) how it change entry point?

I know that from the point of view of the C programming languagemain() is the entry point of the program.But from the point of view of the operating system is __start at ctrt0 startup routines which are linked into a program that performs any initialization work required before calling the program's main() function (correct me if wrong here).So we have some attributes which we can use for our functions, one of them isconstructor attribute which is called before main(), who is responsible to call this function?__attribute__((construtor))void foo(void){ puts("Construc...

 c                     1 answers                     66 view
 2018-10-22         Phoenix

C TCP cannot detect broken connection

This question already has an answer here: Detecting TCP Client Disconnect 13 answers If the peer of a TCP connection closes the connection, it will lead to a recv call on your end to return 0. That's the way to detect closed (but not broken) connections.If you don't currently receive anything from the peer, you need to make up a protocol on top of TCP which includes receiving data.Furthermore, sending might not detect broken connections (like missing cables etc.) directly, as there are ...

 c                     1 answers                     67 view
 2018-10-22         Joanne

warning on 64bit string formatter in mingw environment

What is the correct way to avoid warnings on 64bit printf/scanf arguments on the most recent versions of mingw-w64?I know that mingw-w64 relies on microsoft runtime for many standard library functions, and that these functions are not compatible with C99 standard.Old answers say to use %I64d, but as the C99 standard is %lld, anyway if I compile with -Wall -pedantic I get warning for BOTH syntax, here is a small example:#include <stdio.h>int main(void){ long long test; scanf("%I64d", &test); scanf("%lld", &test);}Compile it with gcc (my version is ming...

 c                     1 answers                     68 view
 2018-10-22         Charlotte

Pre processor: #if comparing two values

I was working on setting up a UART for ATmega168 micro controller. My first code didn't work. While checking on that I came across an header file used in a working program. It uses preprocessor directives. It was quite confusing for me, so I decided to run it in a c compiler and check outputs.#include <stdio.h>#define F_CPU 1000000UL#ifndef BAUD /* if not defined in Makefile... */#define BAUD 9600 /* set a safe default baud rate */#endif#define BAUD_TOL 2#define UBRR_VALUE (((F_CPU) + 8UL * (BAUD)) / (16UL * (BAUD)) -1UL)#...

 c                     1 answers                     69 view
 2018-10-22         Louis

Output not shown correctly

I am a beginner in C programming and I have written the following code but it is producing an error at the output. The code is-:#include <stdio.h>#include <conio.h>void main(){ int n=0; int i,k; char name; printf("\t\t Program to find the overtime of 10 workers\n\n"); for(i=0;i<=10;i++){ printf("Enter the name of worker"); scanf("%char",&name); printf("Enter the number of hours worked"); scanf("%d",&n); if(n>10){ k=n-10; printf("He is eligible for overtime for overtime of rs %d\n",k*12); } else{ k=0; p...

 c                     4 answers                     70 view
 2018-10-22         Suzanne

Changing hardware flow control pins on STM32

I have been reading up on handshaking and hardware flow control for serial communication and I have a question that I can't seem to find an answer to.If you set up hardware flow control for a serial port on cubeMX it will set the pins up that are required. I know you can use alternative pins as well and this can be done through cubeMX. My question is, could you set up hardware flow control manually by using different pins or do you strictly have to use the implemented pins?I am using a STM32F207ZETx and I am using USB as well as serial - however when using the USB periphera...

 c                     1 answers                     59 view
 2018-10-22         Rod

Stray characters seen at output of snprintf

I have a string creating function in C which accepts an array of structs as it's argument and outputs a string based on a predefined format (like a list of list in python).Here's the functiontypedef struct{ PacketInfo_t PacketInfo; char Gnss60[1900]; //and other stuff...} Track_json_t;typedef struct { double latitude; double longitude;} GPSPoint_t;typedef struct{ UInt16 GPS_StatusCode; UInt32 fixtime; GPSPoint_t point; double altitude; unsigned char GPS_Satilite_Num;} GPS_periodic_t;unsigned short SendTrack(){ ...

 c                     2 answers                     61 view
 2018-10-22         Hilary

clang error: linker command failed with exit code 1104

Hi I'm rather new to Windows command prompt(have only been using Linux-based OS)I'm trying to install OpenBLAS for Windows according to this tutorial.When I tried running step 6cmake .. -G "Ninja" -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_C_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DBUILD_WITHOUT_LAPACK=no -DNOFORTRAN=0 -DDYNAMIC_ARCH=ON -DCMAKE_BUILD_TYPE=ReleaseI get the following error Compiling the C compiler identification source file "CMakeCCompilerId.c" failed. Compiler: C:/ProgramData/Anaconda3/Library/bin/clang-cl.exe Build flags: /DWIN32;/D_WINDOWS;/W3 Id...

 c                     1 answers                     51 view
 2018-10-22         Gustave

Should I include both fflush(stdin) and a space in scanf() or will only one of them suffice?

This question already has an answer here: Using fflush(stdin) 4 answers fflush(stdin) is undefiined behavior. int fflush(FILE *ostream); ostream points to an output stream or an update stream in which the most recent operation was not input, the fflush function causes any unwritten data for that stream to be delivered to the host environment to be written to the file; otherwise, the behavior is undefined. [XXX]

 c                     1 answers                     61 view
 2018-10-22         Sophia

how to create a new type with custom bytes in C?

Is it possible to create a new type in C that uses the amount of bytes that I decide? I know that an int takes 4 bytes, but I need to work with very small numbers so allocating 4 bytes with malloc for every int is a bit of a waste, i was thinking of creating a new type for numbers that takes only 1 byte...if it's possible You can just use char instead of intOr, you can create structure, it is the most commonly used custom data type in C.For example:struct customStructure { char c;}; [XXX] Is it possible to create a new type in C that uses the amount of bytes that ...

 c                     5 answers                     62 view

Page 1 of 2144  |  Show More Pages:  Top Prev Next Last