structure

How do I write to a specific line of file in c?

不羁岁月 提交于 2019-12-25 01:28:53
问题 So I have a project I am doing and I have created a program that allows the user to write to a file, as shown below: #include <stdio.h> #include <stdlib.h> FILE *fd; FILE *fw; struct store { char Word[512]; char NWord[512]; } stock; struct store2 { char Definition[512]; } stock2; char done='y'; int count=1; int c=0; int d=0; int main(void) { fw=fopen("Test Z W.txt","w"); fd=fopen("Test Z D.txt","w"); do { printf("Word %d: ",count); gets(stock.Word); while((c= getchar()) != '\n' && c != EOF);

Way/coding method to do activitylist/log

房东的猫 提交于 2019-12-25 01:14:39
问题 Ok so this question is not so much about the coding procedure, but more like a good and clean way to code this activitylist, i plan to build.. This activitylist will contain all activities on the page. So basically on all the actions made on the page, it will call something like a function insertActivity($stuff) to insert the activity about that e.g you just did something. Now I am wondering the coding way, how should I do it? Should I have the message "you just did something" in the row in

Read in from file into structure

寵の児 提交于 2019-12-24 19:35:10
问题 I want to read in from txt file into structure using fstream. I save the data to the file in the way shown below: To read the data i tried some cheeky stuff with getlines or tabsin< struct tab{ int type,use; string name, brand; }; tab tabs[500]; ofstream tabsout; tabsout.open("tab.txt", ios::out); for (int i = 0; i < 500; i++){ if (tabs[i].use==1){ tabsout << tabs[i].type << " " << tabs[i].name << " " << tabs[i].brand << "\n"; } } tabsout.close(); //input part that fails me :( int i=0;

Function Pointers within structures in C

人盡茶涼 提交于 2019-12-24 16:29:50
问题 typedef struct Item{ int i; int j; void (*fooprint)(item*); }item; void fooprint(item *it){ printf("%d\n",it.i); } int main(){ item myitem; myitem.i=10; myitem.j=20; myitem.fooprint = fooprint; myitem.fooprint(&myitem); return 0; } This code gives a error at void ( footprint)(item ). "The error is expected ‘)’ before ‘*’ token ". Am I missing something ? When I do the same without using pointer to the structure is works. Example : void (*footprint)(item) 回答1: The type item is not known yet

accessing Double pointer

…衆ロ難τιáo~ 提交于 2019-12-24 16:10:08
问题 typedef struct _WDF_USB_DEVICE_SELECT_CONFIG_PARAMS { ULONG Size; WdfUsbTargetDeviceSelectConfigType Type; union { struct { PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor; PUSB_INTERFACE_DESCRIPTOR* InterfaceDescriptors; ULONG NumInterfaceDescriptors; } Descriptor; struct { PURB Urb; } Urb; struct { UCHAR NumberConfiguredPipes; WDFUSBINTERFACE ConfiguredUsbInterface; } SingleInterface; struct { UCHAR NumberInterfaces; PWDF_USB_INTERFACE_SETTING_PAIR Pairs; UCHAR

Liferay structure template get Image name

人盡茶涼 提交于 2019-12-24 14:19:31
问题 I have image field in structure for Web Content display: <root available-locales="en_US" default-locale="en_US"> <dynamic-element dataType="image" fieldNamespace="wcm" indexType="keyword" name="image_1" readOnly="false" repeatable="false" required="false" showLabel="true" type="wcm-image" width=""> <meta-data locale="en_US"> <entry name="label"> <![CDATA[Image 1]]> </entry> <entry name="predefinedValue"> <![CDATA[]]> </entry> <entry name="tip"> <![CDATA[]]> </entry> </meta-data> </dynamic

Indexing to get access members of a structure. C programming

走远了吗. 提交于 2019-12-24 14:10:18
问题 Assuming I have a struct typedef struct { unsigned char mem1; unsigned char *mem2 } MEMBERS; where unsigned sample = 12 MEMBERS memvalues = { 0x15 , &sample }; I need to access both values mem1 and mem2, when a function "GET_MEM" returns the address of the structure "MEMBERS" to X_mem. What I mean is this: unsigned char *X_mem = GET_MEM ( ); //function returns address of memvalues unsigned value1 = *X-mem; unsigned Value2 = *++X_mem; I want value1 to give 0x15, and value2 gives 12. How can I

C qsort doesn't sort structure arrays

眉间皱痕 提交于 2019-12-24 14:07:39
问题 I have a program that's designed to read in words and split them apart, separating each and counting them up individually (words with punctuation differences are counted as different words on purpose). typedef struct word { char letters[100]; int count; } Word; int compare (const void *a, const void *b) { return strcmp((*(struct word **) a)->letters,(*(struct word **) b)->letters); } int main() { int sizeCheck = 0; Word ** collection = malloc(sizeof(Word*)); Word * array = malloc(sizeof(Word)

Filling structure from a file

别来无恙 提交于 2019-12-24 13:38:23
问题 Hey guys i am doing a project at school and i need to fill an array of pointers with info from a text doc: 4101 BRAEBURN_REG 1 0.99 101.5 4021 DELICIOUS_GDN_REG 1 0.89 94.2 4020 DELICIOUS_GLDN_LG 1 1.09 84.2 4015 DELICIOUS_RED_REG 1 1.19 75.3 4016 DELICIOUS_RED_LG 1 1.29 45.6 4167 DELICIOUS_RED_SM 1 0.89 35.4 4124 EMPIRE 1 1.14 145.2 4129 FUJI_REG 1 1.05 154.5 4131 FUJI_X-LGE 1 1.25 164.1 4135 GALA_LGE 1 1.35 187.7 4133 GALA_REG 1 1.45 145.2 4139 GRANNY_SMITH_REG 1 1.39 198.2 4017 GRANNY

Swapping structures using pointers

℡╲_俬逩灬. 提交于 2019-12-24 12:26:07
问题 Suppose we have a structure like the following: struct EMPLOYEE{ int EmpID; int Sal; } Stu[5]; And we wish to swap these structures if the following condition is true: Stu[i].Sal < Stu[0].Sal One way way could be by swapping the whole stucture. Something like this: TempStu.Sal = Stu[i].Sal; Stu[i].Sal = Stu[0].Sal; Stu[0].Sal = TempStu.Sal; TempStu.EmpID = Stu[i].EmpID; Stu[i].EmpID = Stu[0].EmpID; Stu[0].EmpID = Temp.Stu.EmpID; This makes it a very time consuming method. Other method could