C :: Creating Simple Address Book Struct - For Loop?
May 11, 2014
My address book will be simple, and the thing's that I'm expecting to use in it are :
Pointers, Linked Lists
Malloc
Structs
Typedefs
Makefile, header file
Putting functions into different program files
I have started the program trying to create a struct, and getting it working with a couple of entries before going onto user input and splitting it up.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
// Struct type address book. Just a name, a number and a pointer
[Code] .....
I'm a bit lost at this point... My knee jerk thought is to create a for loop, and cycle through the list.
I'm not sure how this would apply to this though? Without using the familiar type of print loop such as :
Code:
for (i = 0; ;i++) {
printf("%i
", array[i];
}
I'm thinking that I need to create a temporary struct that can be used to assign the value of the next struct in the list, and then somehow print from that....
I'll try and write the logic out :
while temp != NULL (The last node value is assigned NULL to show us where the end of the list is)
create a temporary pointer that can be used to keep track of where we are in the list.
print out the current entry name and number
then assign the temp pointer value to the * next of the current struct. So if we are in entry1 the *next should be the address of entry 2.
Print out entry 2 name and number, assign entry 2 next to the temp value.
View 1 Replies
ADVERTISEMENT
Sep 3, 2014
This program is an address book where you caan add/view entries. I'm having a problem printing out entries. Why the information isn't getting saved into the structure array?
Code:
#include <iostream>
#include <string>
using namespace std;
struct contactinfo
[Code] .....
View 1 Replies
View Related
Feb 19, 2014
I have to develop an address book for contacts, and it has to be able to add contacts, delete them, and show them all while implementing dynamic memory allocation. I'm thinking I should be going with an array of structures, but I'm not sure how to handle that in the context of this problem. I realize deleting them will most likely end up just being me using the free function. i'm thinking I should show all the contacts with a for loop, but say u deleted contacts, and those memory spaces were now absent, how would I go about it because the looping structure would be flawed wouldn't it.
View 3 Replies
View Related
Dec 6, 2013
the program is of an address book. the syntax is all fine, and the initial menu of options does show up. but once you punch in the cin, the program just stops.
View 9 Replies
View Related
Jul 13, 2013
I have to write a code which would determine either a URL address is correct or not.
Now, a valid address should look like: "www.something.something.uk".
It has to have 3 dots, 3 w-s in the beginning, and it must end with "uk".
E.g.
Valid addresses:
1. www.jce.ac.uk
2. www.tr2213.oi34.uk
Invalid addresses:
1. www2.jce.ac.uk
2. òæøéàìé - îëììä à÷ãîéú ìäðãñä éøåùìéí - ìéîåãé äðãñä ìúåàø øàùåï
3. www.something.uk
Just to be clear, this criteria mentioned above is not real, just homework
Code:
#include <iostream>
#include <string.h>
using namespace std;
int isValid (char s[])
{
int dots=0;
[Code] ......
It tells me both strings are incorrect but the first 1 is.
View 4 Replies
View Related
Feb 28, 2015
Im having trouble creating a struct within a struct node. the program suppose to hold students firstname, lastname, and gpa in a node therefore creating my linked list. Line 26 keeps saying that cannot convert parameter 2 from 'studentType to std::string
#include <iostream>
#include <string>
using namespace std;
struct studentType{
string firstname;
string lastname;
double gpa;
[code].....
View 2 Replies
View Related
Apr 2, 2014
How to get relative memory address of members of Class or Structure ? I want to auto scan the members of Class/Struct, and show the address/value like the "watch window" in debug mode of popular C/C++ IDE software.
View 2 Replies
View Related
May 14, 2012
I am doing a piece of gui code on some embedded system.
I'm trying to find a way of eliminating the local variable kEvent:
Code:
EVENT kEvent;
....
Code:
kEvent = EVENT_UPSTREAM;
xStatus = xQueueSendToBack(getEventProcessorQueue(),&kEvent, 0 );
....
I tried this, it doesn't work:
Code:
xStatus = xQueueSendToBack(getEventProcessorQueue(),(EVENT *)EVENT_UPSTREAM, 0 );
Shouldn't this work?
View 1 Replies
View Related
May 10, 2014
I need to take info in the following format (no blank/skipped lines):
last name, first name street address city, state zip code
And dynamically allocate space for it. I need to use structs, and I need to use an array of pointers to structs to point to them. I know I probably have quite a few problems with my code, but so far, I am able to store and print back the data without issue. In the following code, I only make the loop run 3 times just so I can test it with manual input into the console, but eventually the max will be 50, or until end of input (will be doing IO redirection with a txt file).
Like I said, I can store and print the data fine, but am getting a segmentation fault when trying to sort the info.
Code:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
struct addressBook{
char name [50];
char streetAddress [50];
[Code] ....
View 6 Replies
View Related
Feb 21, 2014
I am new to C programming, I have been given an assignment to create a simple calculator by splitting the program in 3 files. It should have 2 .c files and 1 .h... I went through the internet extensively and could only come up with this.
main.c:
Code:
//Calculator main.c
#include <stdio.h>
#include <conio.h>
#include "Functions.h"
int main() {
float x = 0, y = 0;
int operation;
[Code]...
Functions.c
Code:
#include "Functions.h"
extern float x, y;
float addition (float a, float b) {
return a + b;
[Code]...
Functions.h
Code:
#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED
float Sum(float a, float b);
float difference (float a, float b);
float remainder (float a, float b);
float product (float a, float b);
#endif
When I do a 'cl main.c' on the Developer Command window for VS2013, i get an error that reads :
main.obj
main.obj : error LNK2019: unresolved external symbol _difference referenced in function _main
main.obj : error LNK2019: unresolved external symbol _product referenced in function _main
main.obj : error LNK2019: unresolved external symbol _addition referenced in function _main
main.exe : fatal error LNK1120: 3 unresolved externals
View 5 Replies
View Related
Feb 27, 2014
3. Write a program that reads a sequence of positive integers and prints out their sum, except that if the same number occurs several times consecutively, ignore all but the first. Assume an input of 0 marks the end of the input. For example, if the input is 3 8 5 5 4 9 1 1 1 1 8 0 then you should print 38 (i.e., ignore one of the 5's and three of the 1's).
View 5 Replies
View Related
Feb 26, 2015
1 create a struct called complex which reprensts a complex number . both the real and imaginary compoents should be represented as doubles . ( 1 marks) .
2 write down a function called magnitude which has one parameter ( a struc complex) and a return type of double . it should return the maginude of the given parameter . ( 3marks) .
3 write a function called find_largest which has two parameter (one of type struct complex const * and the other type int) and a return type of struc complex . the two parameter represent an array of complex numbers and number of elements in that array . the function should return elements from array which has largest magnitude . this fucntion must called the magnitude function . ( 5 marks)
4 write a main function . your main fucntion . Your main fucntion should repeately prompt the user for complex number , storing them in an array. you should continuing reading in complex number until the user enters in both componets , at this point you should stop . you should not make an assumptions how many complex number the user will enter , ( i.e use realloc) after reading in complex numbers from the user you should print out real and imaginary components of the complex number with the largest magnitude.
Code:
#include<stdio.h>
struct complex {
double real;
double imag;
[code]....
View 5 Replies
View Related
Apr 30, 2014
I know for while loops you type
while(argument){
do whatever
}
you have to use the brackets to enclose just like I used in my code right here.It is a simple while loop that is a countdown.
#include <iostream>
using namespace std;
int main() {
int n =10;
while(n>0){
cout << n << ", ";
[code].....
when I take the brackets away from my while loop, my code will still execute but it just prints out the number "10" repeatedly. I was just wondering why it does this and why the compiler does not throw out an error when I leave off the brackets after the "while()".
View 10 Replies
View Related
Jun 30, 2013
I have a problem with my simple operations calculator code (using C, in Code::Blocks). I am required to use a while loop statement so the user can execute multiple step operations without re-opening the program. When I launch the program, I get through the first session fine, but when I'm on the second session, when entering the two operands and press enter (to calculate), it just gives me the return and say press any key to continue (exit).Here is the code:
Code:
# include <stdio.h>
int main()
{
int num1, num2;
char op;
int finished = 0;
}
[code]....
View 8 Replies
View Related
Nov 6, 2013
trying to output my struct to a for loop. I understand how to output the struct but not into a for loop.
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
struct Date {
int day;
int month;
int year;
[code]....
View 16 Replies
View Related
Apr 28, 2014
I need starting a do-while loop in my program that runs up to 10 time that asks the user to enter up to 10 scores, which include the slope and rating for the course, and calculates the handicap for each score.
Here's what I have so far:
Code:
{
//This program calculates a golfers handicap.
#include <iostream>
#include <string>
using namespace std;
[Code] ....
View 1 Replies
View Related
Mar 21, 2014
I am trying to create a code and cannot get the following part to work :
for (int n = 0; n = timesteps; n++)
{
n = n + 0.1 ;
cout<< "timesteps"<< n << endl ; //print time step value =0.1
for (int j = 0; j < nodesinx; j++)
{
T[j][n+1] = T[j][n] + 0.16 * (T[j][n] - 1[n] - 2[T[j][n] + T[j] + 1[n] ; //equation
n= n + 0.1 ;
cout<< "temperature" << T[j][n+1] << endl;
T[j][n+1] = 0.0 ;
}
}
View 1 Replies
View Related
Oct 13, 2014
I am creating a binary search program that lets the user input up to 10 integers and then the program displays the array and sorts it. When the user is prompted to select an integer, if the integer is in the array, the program responds with the array subscript part. I can get the loop to work once and maximum twice, but then it wont search for the array or say value not found even though the number in in the array. I tried making the values NULL but that only lets me go through it one more time.
Here is my code:
#include <iostream>
using namespace std;
//Functions
void printArray(int);
void selection(int);
int binarySearch(int,int,int);
[code]....
View 6 Replies
View Related
Aug 13, 2014
From the example given below, I would like to Generate a matrix who stores a generated array for each iteration. I have an understanding of inputting single elements to a matrix but how can I input an array to a matrix. let's say I would like to input and array of 4 elements that should be stored as a single row of the generated matrix and do this for an infinite while{true} loop.
#include <iostream>
#include <unistd.h>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
void printArray(int arr[], int size) {
[Code] ....
View 7 Replies
View Related
Apr 29, 2015
I am attempting to create multiple labels in a for each loop for each tag text (using htmlagility pack). My current code only creates one and doesn't change the first value (Which is AAE). I am using the labels to later input all the label.text into a database after the initial loop has finished (not shown).
foreach (var tag in tdTags) {
MessageBox.Show(tag.InnerHtml);
Label label = new Label();
label.Name = "contentName" + tag.InnerHtml;
label.Text = tag.InnerHtml;
[Code] ....
View 3 Replies
View Related
Oct 30, 2014
I have this if block that is supposed to be creating a pipe then forking and I would like to combine the while loop below it with it. How would I do that?
p = pipe(pipe1);
if (p < 0) {
printf("pipe error");
exit(0);
} else {
printf("successful pipe1 = %d",p);
[Code].....
I have trying to read this documentation but don't understand it. [URL] ....
View 1 Replies
View Related
Apr 6, 2014
I am currently having problems creating a loop that will allow my user to choose to return to the beginning of the program or quit.
#include <iostream>
using namespace std;
int main() {
int j;
do {float a;
cout << "+----Welcome to Basic Operations----+
| Select Your Operation |
[Code] .....
I have not yet finished designing the interface for a couple of the operations, but right now i am hung up on trying to return to the beginning. I believe it is because the j was defined inside do and isn't carried out of the do statement for while.
View 13 Replies
View Related
Jul 14, 2013
I am trying to create a loop to call in the entries from the text file named Set. The entries of Set.txtare :
1 2 3
2 4 5
and so on .. (64 such combinations)[/CODE]
It basically means the first combination for testing is 1 2 3 and next has to be 2 4 5 and so i have 64 such entries defined in set
My test files are located in D://data// and are named tst_data1 to tst_data64.
I created a loop for test set but its incorrect
Code:
// loop for test samples
char basefilename[] = "D://data//";
char , testFilen[160], numiChar[10];
for (int i=1; i<=64; i++) {
strcpy(basefilenme, "D://data//");
strcat(testfilename, Set[]);
[Code] .....
How can i call the Set .txt and how to define it.
View 1 Replies
View Related
Sep 15, 2013
I am trying to make a grade book and using a vector to get the grades. I am getting errors all over and I figured this would happen because this is the first time I ever used vectors.
Code:
#ifndef ___2B__Homework__LetterGrade__
#define ___2B__Homework__LetterGrade__
#include <iostream>
#include <vector>
[Code] .....
View 12 Replies
View Related
Feb 7, 2013
Book database. I use scanf to store book name,author name and year when is book written. Example:
Code:
scanf(" %[^
]",k[i].bookname);
I have problem when i want to printf all books from database with this:
Code:
for(i=0;i<counter;i++){
fscanf(f,"%s %s %d",k[i].bookname,k[i].author,&k[i].year);
printf("
%d %s %s %d",(i+1),k[i].bookname,k[i].author,k[i].year);} Output:
Number Book name Author name Year
1 King John 0
2 William Shakespeare 1590
How can i fix this?
View 4 Replies
View Related
Jan 15, 2015
I'm writing a program that uses the readline() function that comes in the Unix Network Programming book, when I use telnet to connect to my server the function reads the input perfectly displaying the username as the user types it in. However, when using a telnet client called syncterm it accepts the user input but does *not* echo it on the screen and I can't figure out why.
View 3 Replies
View Related