So, I'm using allegro game programming library. Before I move on to bigger and better things I wnat to get a handle on pointers. Specifically with things like structs, linked lists and maybe binary trees in the future. I posted a program that uses a linked list to keep tracks of a variable number of objects on the screen. GDB tells me it fails in the main also, the new style of posting is kinda buggy, for example I can move the cursor past the program code. gdb: Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: …

Member Avatar
Member Avatar
+0 forum 3

Hi everyone, I'm facing problem in deleting a node in **del()** used in my program. Suppose, i've added a city as **Delhi**, and at the time of deleting, i type the name as **delhi**, the compiler gives a processor fault. But, i want it to display the line number **95**. I found out that there is error in while part in line number **85**, but i dont know how to overcome that problem. Anyone there to help me out with this???????????????????????? NOTE: I dont want to use any extra integer to detect the position. My program: #include<conio.h> #include<stdio.h> #include<string.h> #include<alloc.h> …

Member Avatar
Member Avatar
+0 forum 8

so the code is pretty simple. it just loops and if statements. first i have a main. i took the headers and prototypes out to make it smaller. In main all iam doing is asking user to enter command and call one funtion. // main.c int main(int argc, char *argv[]) { char command[10]; printf("Enter (a) to slove Linear equation(1 variable):\n");fflush(stdout); printf("Enter (b) to slove Linear equation(2 variable):\n");fflush(stdout); printf("Enter (slope) to find Slope\n");fflush(stdout); printf("Enter (exit) to Exit:\n");fflush(stdout); scanf("%s", command); while(strcmp(command, "exit") != 0) { if(strcmp(command, "a") == 0) { linear_1(&buff1, &buff2); } printf("Enter (a) to slove Linear equation(1 variable):\n");fflush(stdout); printf("Enter (b) …

Member Avatar
Member Avatar
+0 forum 2

Hi i had never before used structures, so i am a complete noob ;) . this is a small Part of my programm: struct player { int var1; int var2; int var3; int var4[10]; int var5; int var6; }; struct player p[4]= {{1000,0,0,{0,0,0,0,0,0,0,0,0,0},0,1}, {1000,0,0,{0,0,0,0,0,0,0,0,0,0},0,1}, {1000,0,0,{0,0,0,0,0,0,0,0,0,0},0,1}, {1000,0,0,{0,0,0,0,0,0,0,0,0,0},0,1}}; printf("%d\n"), p[0].var1; printf("%d\n"), p[0].var2; printf("%d\n"), p[0].var3; printf("%d\n"), p[0].var4[0]; printf("%d\n"), p[0].var5; printf("%d\n"), p[0].var6; getch(); But the initialization doesn't work! i get the follow numbers: var1: 1090519874 var2: 1090519874 var3: 1090519874 var4[0]: 1090519874 var5: 1090519874 var6: 1090519874 Can someone help me pls? p.s: sorry for the bad english :(

Member Avatar
Member Avatar
+0 forum 2

#include<stdio.h> #include<stdlib.h> struct student{ char *name; int number; }; struct class{ char *name; struct student *st_array; // pointer of array of students int size; // All students free places int current_size; // Occupied places }; struct student make_student(char name[100], int number){ struct student st; st.name = name; st.number = number; return st; } struct class make_class(char name[100], int length){ struct class cl; cl.name = name; cl.st_array = malloc(sizeof(struct student) * length); cl.size = length; cl.current_size = 0; return cl; } void add_to_class(struct class* cl, struct student st){ if(cl->current_size < cl->size){ cl->st_array[cl->current_size] = st; cl->current_size++; }else{ printf("You overflow student size of …

Member Avatar
Member Avatar
+0 forum 1

So, basically im using the codea bove to generate coordinates for a grid, but I only want to generate coordinates for the "outer ring" of a square. SO imagine a grid of 7x7, I won't generate coordinates for the inner 5x5 square, only for the outer ring. Basically I drew it all out on paper, used fake numbers and based off that I came up with t his logic that can be changed around. In the code "25" is used as dummy data for the distance between the center of one square and another. The 150 that you see can …

Member Avatar
+0 forum 0

I wrote this program... Just gave a try!! i got a problem with searching a string in file.. the **"checkp"** used in the login function, returns a value **"1"**, whereas it must return a value **"0"** Hence my program fails... what i felt is, the file i'm opening, **"web_reg.txt"**, in that, extra spaces are coming... Does anyone knows, to sort this out???? Please help me!! please check it out in your PC's. Thanks a lottt **The code is as following:** #include<conio.h> #include<stdio.h> #include<string.h> struct web { char name[30],pass[30]; }w; int n; void login(void); void reg(void); void main() { clrscr(); printf("\n\n\n\n\n\t\t\t\tWELCOME …

Member Avatar
Member Avatar
+0 forum 11

iam trying to store all the data in to a struct so i can change it later. //this data is in file abc 1 11 22 def 2 33 ghi 0 22 11 33 asd 2 i was planing on making a array of structs. so 1st line will have one struct. 2nd line will have 2nd struct. struct node { char *alp; int x; int ar[]10; }; int main() { int i = 0; char *array[20]; struct node buff {NULL, 0, 0000000000}; while(read one line(LOOP) fscanf()) - array[i] = buff->alp = abc; - array[i] = buff->x = 1; - …

Member Avatar
Member Avatar
+0 forum 5

Does anyone knows how to assigned directly the sqlite query result to a struct in C rather that assigning to its members one by one? I have a table user_info with fields user_id, username, password. Also I have a struct st_user_info. typedef struct st_user_info{ int userId; char* userName; char* password; } T_USERINFO; T_USERINFO tUserInfo[10]; I want my query result from `sqlite3_step` to be assigned direcly to the `struct tUserInfo[index]`. Is there a way to achieve on this way?

Member Avatar
Member Avatar
+0 forum 1

I want to create a struct array and get the max number of books written by particular author...The problem is that i can't get the number. I am not finished up yet with the code,but i don't know why i am not getting anything when calling the Max function.Please advise! I had recently started learning C++,so bear with me! [CODE] #include <iostream> #include <cstring> using namespace std; struct book { char author[50]; int number; }; void input_info(book *m,int n) { for (int i=0;i<n;i++) { cin.ignore(); cout<<"Enter author's name: " << endl; cin.getline(m[i].author,50); cout<<"Enter the number of books written:" << endl; …

Member Avatar
Member Avatar
+0 forum 2

can you help me with these a little problem of mine.. we are having a pair project where the program is all about enrollment system. in this program, we need to add a record, view, and search records. now. my problem is... i cannot add another record within this code... [ICODE] #include <iostream> #include <cctype> #include <sstream> #include <string> #include <conio.h> #include <windows.h> using namespace std; struct TOSAVERECORDS{ string firstname[true], lastname[true], middleinitial[true], gender[true], address[true]; int age[true]; } RECORD; int main () { int selection; string searchrecord; int tempforarray=0; string hold; start: string temp1, temp2, temp3, temp4, temp5; int temp6; char …

Member Avatar
Member Avatar
+0 forum 2

Hello everyone, I have a program that intends to create a doubly linked list of structures, using the following header (q1.h): [CODE=c]typedef struct lNode* ListNodePtr; typedef struct lNode { char* string; ListNodePtr next; ListNodePtr prev; } ListNode; [/CODE] This is my implementation: [CODE=c]#include "q1.h" #include <stdio.h> #include <stdlib.h> #include <string.h> ListNodePtr tail = 0; ListNodePtr newNode(void); ListNodePtr addNode(ListNodePtr h, char *w); void printList(ListNodePtr h); void deleteNode(ListNodePtr h, char *w); ListNodePtr newNode(void) { ListNodePtr n; n = (ListNodePtr)malloc(sizeof(ListNode)); n->prev = 0; n->next = 0; return n; } ListNodePtr addNode(ListNodePtr h, char *w) { ListNodePtr a; if (h == 0 && tail …

Member Avatar
Member Avatar
+0 forum 30

Hi, I have a task to perform which all to do with the smurfs, reading from a file and doing some simple stuff to it. The last part I need to do is print out a list of all smurfs and their corresponding role in alphabetical order. I am hoping I can do this using the qsort function but this is giving a segmentation fault. I have attached my code below: [CODE] #include <stdio.h> /*Required for file operations*/ #include <string.h> /*Required for strlen etc*/ #include <stdlib.h> /*Required for Malloc,Free, etc.*/ /*-----------------------------------Declarations----------------------------------*/ FILE* fp; /*Declare the file pointer*/ char str_read[50]; char …

Member Avatar
+0 forum 0

[CODE]#include <stdio.h> #include <stdlib.h> #include <string.h> //typedef struct to define what's in the phonebook typedef struct PhoneBookContacts { char Name[20]; char Surname[20]; char PhoneNumber[20]; } phone; //Function prototypes void AddEntry (phone[]); void DeleteEntry (phone[]); void PrintEntry (phone[]); void Sort (phone[]); int counter = 0; //Global counter variable used to keep track of number of contacts //Begin main function int main (void) { phone phonebook[20]; //Phonebook instance char userChoice; //Variable to use to select menu choice while (userChoice != 'Q') { printf ("***************\n"); printf ("Please enter a command:\n"); printf("'A': Add an entry\n"); printf("'D': Delete an entry\n"); printf("'S': Sort entries\n"); printf("'P': Print …

Member Avatar
Member Avatar
+1 forum 7

Hello! I have a problem. I can't use scanf() to set a value of the second member of the person struct. Why? I get an error that tells me "bad access". [CODE]int main(int argc, const char * argv[]) { struct Adress{ char *street; char *postal; int zip; }; struct Person{ char *firstName; char *lastName; struct Adress home; }; struct Person newPerson; printf("Enter your first name and last name: \n"); scanf("%s %s", newPerson.firstName, newPerson.lastName); printf("Hello %s %s! \n", newPerson.firstName, newPerson.lastName); }[/CODE]

Member Avatar
Member Avatar
+0 forum 4

Hi Programmers, Please help me, i was wondering on how to create a simple phone book program using struct array to insert a new contact, update an existing contact, delete an existing contact and to display the contact information

Member Avatar
Member Avatar
+0 forum 4

Hey everyone, I wrote some code to create a deck of cards, described the deck and randomly deals 5 cards. First, I want to let everyone know that this is homework for my C-II college class, so I am not looking for any answers, but solutions or guidance in figuring out what I am trying to do. What I want to do with this deck of cards is to shuffle the deck and then deal 5 cards, while not dealing the same cards in that hand. IE: Program deals 5 cards. The 5 cards are as follow (I actually ran …

Member Avatar
Member Avatar
+0 forum 6

Hi guys ! I've made a program that marks a seat taken X in an airplane .. So, here's what I've done.. it runs , but when i try to input other seat code, i.e., 1G, the no.2 in the grid becomes 88.. and I don't know how did that happen and how to fix it.. Please help me . Thanks . :) [CODE]#include <stdio.h> #include <conio.h> int x, y ; char s, z=1; struct grid { char upuan[5][5]; }seats; void main(){ clrscr(); void GRID(); void SEAT(); GRID(); SEAT(); getch();} void SEAT(){ int v; char chose[3]; void display(); printf("\n\nWhat seat?:\t"); …

Member Avatar
Member Avatar
+0 forum 6

I have been having trouble developing a function that frees all of the memory associated with structs of a linked list. Im not asking for a clear cut answer, just an idea or a function that can aid. F.Y.I. the linked list contains a head struct and a tail struct to identify the Here's some code that might spark some thought: [CODE]void deleteAllStructs(void){ struct structTypeName listingPtr; do{ for(listingPtr=gHead;listingPtr->next!=NULL;listingPtr=listingPtr->next) ; listingPtr = NULL; while(gHead!=NULL); }[/CODE]

Member Avatar
Member Avatar
+0 forum 6

Hey, so as you can tell, this is my first attempt at writing a class. I put in a mock int main() in order to follow what exactly is going wrong. As far as I can tell, every time the struct in push is used, it always has the same address. The idea is 'first' is the first struct that's pushed onto the queue (using setValues) and 'last' is the most current value pushed onto the queue. I haven't really gotten to working with pop, but I don't need it to return a value, in case you're wondering. Really appreciate …

Member Avatar
Member Avatar
+0 forum 3

Hello there..i'm trying to implement a tree in C#..the basic node structure is give below [code] struct node { public int _x; public int _y; public int _cost; public node _parent; public pos(int i, int j,int cost,pos parent) { _x = i; _y = j; _cost = cst; _parent = parent; } } [/code] I get the following error when i try to compile : 'node' causes a cycle in the struct layout This was the way we used to make a tree in C++..but it's confusing in C#..could anyone please enlighten me?? Any help would be appreciated.

Member Avatar
Member Avatar
+0 forum 2

Hello all, I'm having a bit of trouble logically figuring out what to do in this case for my cs150 class. I have to create a linked list from a while loop, but I can't figure out how to link the list successively at the end of each line so that it creates a nice chain. My original thought was to create a node outside the loop, read the first line, then start the loop at line 2 and after each struct is filled, link the first to that one, create a second temp node to link to the first, …

Member Avatar
Member Avatar
+0 forum 2

I am new to structs and I am trying to sort an array of structs but I can't seem to get it to work, I can't figure out what I am doing wrong and any assistance would be very much appreciated! [CODE]#include <iostream> #include <fstream> #include <iomanip> using namespace std; const int SIZE = 30; struct people { string last; string first; string telephone; }info[SIZE]; void input_data(ifstream& in_data, people info[]); //void sortValues(people info[]); void bubbleSort(people info[]); int main(){ int x; ifstream in_data("directory.txt"); if(in_data.fail()){ cout << "Can't open the file\n"; cin.get(); return(0); } input_data(in_data, info); //sortValues(info); bubbleSort(info); cout << info[0].last << …

Member Avatar
Member Avatar
+0 forum 4

i am receiving a struct from the switch: [CODE]/* Packet received on port (datapath -> controller). */ struct ofp_packet_in { struct ofp_header header; uint32_t buffer_id; /* ID assigned by datapath. */ uint16_t total_len; /* Full length of frame. */ uint16_t in_port; /* Port on which frame was received. */ uint8_t reason; /* Reason packet is being sent (one of OFPR_*) */ uint8_t pad; uint8_t data[0]; /* Ethernet frame, halfway through 32-bit word, so the IP header is 32-bit aligned. The amount of data is inferred from the length field in the header. Because of padding, offsetof(struct ofp_packet_in, data) == sizeof(struct …

Member Avatar
Member Avatar
+0 forum 2

Hi, I'm trying to make a set of monsters that have values that can be loaded. Like a Goblin having enemyhealth = 50, enemydamage = 15, etc. Here's what I kinda have an idea of doing... But I really have no idea how to use it. (File containing values for enemies) Monsterreader: [CODE]#include <iosteam> using namespace std; struct Archer { char enemyname[25] = "Archer"; int enemyhealth = 55; int enemydamage = 15; int enemydefense = 5; } ; struct Goblin { char enemyname[25] = "Goblin"; int enemyhealth = 30; int enemydamage = 13; int enemydefense = 10; } ; [/CODE] …

Member Avatar
Member Avatar
+0 forum 2

Hi guys, what I'm trying to do is allow the user to add a new student record to the system. If the user inputs a student ID already existing in the system, it doesn't accept the ID, but if it's a new student ID, it asks the user if they want to add the student to the system. When the user opts 'Y', it crashes! It's not supposed to! Here's the relevant code: [code] case 6://add a student record { int first = 0; int last = NUMRECS; int mid; int studentCount, newStdCourseCode, newStdCreditPoint; studentCount = NUMRECS; char decision3, option2, …

Member Avatar
Member Avatar
+0 forum 11

Hello guys, just wondering why my program crashes when I try to delete a struct from my array. I'm trying to code so that the user searches for a student via a student ID, then opt to delete the searched student's record. I thought I got it right and the search works fine, but it crashes when I opt to delete the student's record! I know it's due to the actual deleting part in my code. Here's my whole code: [CODE]#include <iostream> #include <iomanip> #include <string> using namespace std; void clrscr() { system("cls"); } void pause() { system("echo.");system("echo.");system("pause"); } void …

Member Avatar
Member Avatar
+0 forum 10

Hi, I am using WinSock library for sending data over network, and I have a problem. I know how to send data in one struct and receive it on the other side, because there is constant size of structure. But what if I have more structures, each one with different size? Now I have one struct that contains locations of players and other with in-game messages. When I am about to receive struct, I don't know which one is being sent. Is there a "trick" how to do that? Thanks for help.

Member Avatar
Member Avatar
+0 forum 7

Howdy, I have a few questions regarding the use of ctime within a class. I followed the example on [URL="http://www.cplusplus.com/reference/clibrary/ctime/strftime/"]http://www.cplusplus.com/reference/clibrary/ctime/strftime/[/URL] When the program is like this, it works: [CODE] #include <ctime> #include <iostream> using namespace std; int main(){ time_t current_seconds; current_seconds = time(NULL); //Fills current_seconds with the number of seconds since January 1, 1970 struct tm * timeinfo; char buffer [80]; time (&current_seconds); timeinfo = localtime (&current_seconds); strftime (buffer,80,"Event Date: %x",timeinfo); //Modifies timeinfo into a user readable format puts(buffer); // Posts the string "buffer" strftime (buffer,80,"Event Time: %X %Z",timeinfo); puts(buffer); return 0; } [/CODE] [B]Question 1[/B]: Is it possible to …

Member Avatar
Member Avatar
+0 forum 3

In structure hen i read floating point value from user and i get the error like"floating point not conneted..." i have been sugested to write two lines for that extern void float conetor(); #pragma extref floatconnector even though i got the same error it is not even asking for float value input. so is it like system dependent or what?

Member Avatar
Member Avatar
+0 forum 6

The End.