C :: Trying To Use Array Of Pointers To Alphabetize String

Dec 8, 2013

I am trying to alphabetize 3 different strings by comparing the first letter in each one. It will work for the first two names, but when I try to print out the third, I keep getting errors and I don't know why?

Code:
#include <stdio.h>
char personName();
int main() {

personName();
return 0;

[Code] ....

View 4 Replies


ADVERTISEMENT

C :: Dynamic Array Of Pointers To String

Jun 11, 2013

I have a little problem with one of my functions. The function purpose is to get a number (n) and create an array (size n) with pointers to strings (each string length is 20 chars) and i don't know why but during the debugging i get a <bad ptr> message and this message :

CXX0030: Error: expression cannot be evaluated

This is my function:

Code:
char** getlist(int n) {
int i=0;
char **arr;
arr=(char**)malloc(sizeof(char)*n);
if (arr==NULL)

[Code] ....

View 8 Replies View Related

C :: Create Array Of Pointers To Pointers Which Will Point To Array Of Pointers

Feb 28, 2014

I'm trying to create an array of pointers to pointers which will point to array of pointers (to strings) I tried

Code:

int i;
char *string[]={
"my name is dave",
"we like to dance together",
"sunny day",
"hello",

[code]...

the app keeps crashing , I don't know how to make the array-elements to point to another array-elements..

View 4 Replies View Related

C++ :: Alphabetize With Different Strings?

May 14, 2012

How would I alphabetize this with the different strings? Would I just need to use a bubble sort?

Code:
#include <iostream>
#include <string>
#include <fstream>

[Code]....

View 11 Replies View Related

C/C++ :: Read A File And Alphabetize?

Aug 29, 2014

I have been working on this program that reads an input file, then reads it, prints its averages and min and max, then writes a new file which organizes the names alphabetically and gives them a grade. I could assume the grade print in the new file could be easy enough with if statements, but I am stuck on how to get the names organized and print them by first name.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

[Code].....

View 10 Replies View Related

C++ :: Program Doesn't Alphabetize Strings

Jan 18, 2015

I can't seem to get my program to alphabetize a vector string. It displays the names, but not in a sorted order.

void sort_names(vector<string> &nameList) {
int i, minIndex;
string minValue;
int size;
size = nameList.size();

[Code] ....

View 4 Replies View Related

C :: Trying To Flip A String Using Pointers

Sep 12, 2013

Having some trouble with basic stuff while learning C. My purpose was to flip the pointing order, so it would point to the string from the end to the start. didn't work so well using **str as well.

Code:
#include <stdio.h>
#include <conio.h>
char str_inve(char *ptr);

[Code] .....

View 10 Replies View Related

C :: Reversing A String Using Pointers

Nov 13, 2013

everything seems to be right in this program except that the puts() function does not print anything.

Code:

/*c program to reverse a string using pointer*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
}

[code]....

View 4 Replies View Related

C++ :: How To Convert A String To Int Without Pointers

Apr 22, 2014

My teacher has done a very poor job of teaching us anything this year. When he taught us for loops, he wrote one on the board, didn't explain any of it, then said now that you know for loops we can implement them in a code. but anyway, we need to write a code for converting a string to an int and all the examples i find on the internet use pointers but we aren't allowed to use those yet.

View 2 Replies View Related

C :: Dynamic Allocation Of String Pointers

Mar 12, 2014

The snippet below (or similar) compiles and runs OK but I am using Visual Studio C++ compiler. Are the lines where .nameFirst and .nameLast assigned kosher in ANSI C?

Also I am concerned about the memory allocation for these string constants. Does the runtime system put them on the heap? It doesn't seem that they are really constants since they are not defined before runtime.

Code:

#include "stdlib.h"
typedef struct
{
unsigned id;
char* nameFirst;
char* nameLast;
} myList;

[Code]...

View 4 Replies View Related

C :: Copying Characters From One String To Another With Pointers?

Apr 14, 2013

So I'm writing a function isPalindrome() that can accept a string as an argument, and copy from it only the alphabetic characters in the argument (original) string to another string named alpha_array which contains only the alphabetic characters. Then the function should be able to call the isPurePalindrome function to determine if alpha_array is an ordinary palindrome.

The problem is that when I call isPalindrome in main, the program crashes.

Here's the code I have for isPurePalindrome and isPalindrome:

Code:

/* 1 */
int isPurePalindrome( const char * sentence ) // Can accept strings, array and pointer arguments
{
// Declarations

[Code].....

View 4 Replies View Related

C :: Pointers And String Manipulations - Finding Correct Path

Mar 11, 2014

i've been writing some code for an assignment and it is mostly about pointers and string manipulations. It runs but crashes and I think it might be from over- valuating some strings maybe not. I have written in check points to make sure each function passes through but quits at findFirstPath loop, I had kept running the program through as i added more and more code. It had stopped when I near finished I believed it to just be because I hadn't finished the functions I called.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAXSTRING 10
#define TRUE 1

[Code]....

View 3 Replies View Related

C++ :: Allocating Array Of Pointers To Dynamically Allocated Array?

Jan 18, 2014

I'm trying extremely hard to understand pointers and I have the basic concept down.. I feel as though my knowledge of dynamically allocated pointers and pointers in general is not enough to understand the logic behind what I'm trying to do. The problem is that the donations array must be able to accept any number of donations. I've made it do just that, but there is also an array of pointers which must each point to the same element in the donations array. The program works if I assign int *arrPtr[100] for example, but it does not work if I try to dynamically allocate it to accept the same number of elements for donations entered by the user. Here it's the snippet

#include <iostream>
using namespace std;
//Function Prototypes

[Code]....

View 2 Replies View Related

C/C++ :: How To Initialize Array Of Pointers To Array Of Characters

May 21, 2014

I am trying to initialize an array of pointers to an array of characters, I can do it in 3 lines but I really want to do it in one line at the same time keeping the #define.

3 lines initialization (can compile)
======================
#define A 1
#define B 2
char row1[] = {A|B, B, A};
char row2[] = {B, A};
char *test[]= {row1, row2};

1 line initialization (failed)
===============================
char *test[] = { {A|B, B, A}, {B, A} }; // <- how do i do this??

I do not want this because it waste ROM space
=============================================
char test[][3] = { {A|B, B, A}, {B, A} };

View 18 Replies View Related

C :: Array Of Pointers To A Struct?

May 10, 2013

I am working on an assignment identical to another post from a couple years ago, for reference here is the thread:

array of pointers to structures sorting addresses by zip code

They way it is written on that thread is almost identical to the way the teacher implied to have it done (only wrote part of the input block). But I am having an error:

When it gets to the output section it outputs then next name along with the zip code... I tried strncpy and strxfrm but both cause more problems than they did work.

The last part of the project is to have the output put out in order of least zip code to most zip code (00000<99999), so this is causing me a real problem and I do not see what exactly is making this happen.

Here is my code (we dont HAVE to use gets but professor suggested using it for this assignment, next lab is to rewrite this using files and fgets rather than I/O redirection):

header.h Code: #ifndef lab_6b_7b_Header_h
#define lab_6b_7b_Header_h
//header file intiating other headers
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{

[code]....

I have not started the sorting code because I cannot get past this, but once I have proper zip codes I am sure I can make a sort function no problem.

I am using xcode with some breaks to read variables as various points and do not notice anything wrong until it makes it to the output functions, although this page briefly pops up between input and output functions when the breaks are up:

View 8 Replies View Related

C :: Array Of Pointers To Strings

Mar 6, 2015

I'm wondering how to access Buffer 1 and 2 via the pointer array;

Code:
char *BufPtrs[3];
char Buffer1[64];
char Buffer2[64];
BufPtrs[0] = Buffer1;
BufPtrs[1] = Buffer2;
BufPtrs[2] = NULL;

I thought that if I were to access Buffer1 via BufPtrs[0], I would simply just put an * to it before printf()-ing or store it in a char[] (equivalent to a string).

View 2 Replies View Related

C :: Array Containing Pointers To Structures?

Aug 9, 2013

How do I store pointers to a struct in an array ? I am using sprintf to concatenate some values together and then output it to an array in its 1st argument. A portion of my code is shown below.

Code:

int count = 0;
struct addx {
int a;

[Code].....

View 1 Replies View Related

C++ :: Using Array Of Pointers To Objects?

Sep 27, 2013

I've created an Array of pointers to objects using:

Person ** A = new person * [arraysize];

When I intend to access a specific person do I have to do this? :

something = A->[i];

and when I want a specific object within my struct do I have to do this? :

something_else = A->[i]->random_int;

View 10 Replies View Related

C++ :: Pointer To Array Of Pointers

Feb 10, 2013

I'm just trying to get a handle on the uses of pointers here. Though clearly from my errors I'm missing a key concept. Here is my code: (You can assume that the array, "array_size" has values in it, I did this part in another function)

int main() {
bool **ptr_array;
int num;
int *array_size;
cin>>num;

[Code] ....

Once the program reaches the word[num] = false; some unhandled exceptions pop up.

I simplified my code a bit from my actual program and mixed up the loops, now the code should be in its correct form.

View 4 Replies View Related

C++ :: Pointers To Array Of Structs

Feb 14, 2013

I have an assignment where I need to use pointers to do a few things and I am a little confused on the syntax of it all. My question is how do you use a pointer to point to an array of structs.

For example

struct info{
char firstName[15];
char lastName[15];
};
main() {
info person[4];
cout << "The third letter of the second persons first name is: "; // ?????
}

how would I define a pointer to point to the third letter of first name the second person in the "person" array.

View 2 Replies View Related

C++ :: Array Of Pointers To Objects?

Dec 5, 2013

my code:

int OKCount=0;
int WaitingCount=0;
int ReservationCount=0;
Flight::Flight(int capacity, int waitingMax) {
seats=capacity;

[code].....

reservations is a data member in the class flight as:

Reservation **reservations;

OKReservation is a derived class and its abstract base class is Reservation.

My problem is that the reservations array loses its value in other function

View 8 Replies View Related

C :: Bsearch In Array Of Pointers To Struct

Mar 6, 2015

What I'm trying to do with this code is an address book and I have an array of pointers which are returned by malloc whenever I need to add an extra entry in the address book. What I need to do is search for a specific entry using bsearch. I've got an inqSort() function that sorts the table and runs normally, but my program crashes when I try to use bsearch.

Code:
typedef struct {
char name[20];
char phone[14];
} abEntry;

[Code] ....

Every time an entry is inserted, I inqsort() the array so it's always sorted, and it works as expected. But when I try to call findEntryUI(); from the main() function, the program crashes after entering the name I want to search.

View 3 Replies View Related

C :: Reading A File Into Array Of Pointers?

Mar 24, 2013

why when I print out "array[2]" nothing prints? It just prints blank space. My file definitely has text in it, but when I try to assign "text" into the array of pointers it won't show any text. I know fgets() appends a newline at the end of the string, not sure if that has anything to do with it, but I've tried printing everything that should be in "array" with a for loop and I get nothing.

Code:
#include <stdio.h>
#define FILEPATH "/home/user/Desktop/text"
int main(){
FILE *myFile = fopen(FILEPATH, "r");
if(myFile == NULL) return 0;
char text[100];
char *array[100];
int idx = 0;
while(fgets(text, 100, myFile)){
array[idx++] = text;
}
puts(array[2]);
}

View 2 Replies View Related

C :: Static Array Of Function Pointers

Jan 29, 2015

I basically have some code that lets users register callbacks into a callback table at a specified index. There is one element in this table for each event that can trigger a callback. I basically do something like this:

In a header file

Code:
typedef struct _GMclient
{
GMcommunicator gcomm;
GMclient_callback callback_table[(int)MAX_CALLBACKS];
}GMclient;

typedef int (*GMclient_callback)(GMclient*, void*, void*);

Then I allow them to set the callback with a function that basically ends up doing this (in a .c file that includes the previous mentioned .h file):

Code:
void
GMclient_register_callback(GMclient *client,
GMclient_callback fxn,
int index)

[Code] ....

Then later when I need to invoke that callback, I pull it out of the table

Code: GMclient_callback *fxn = client->callback_table[CMD_INDEX];

However, I get compilation errors:

Code: src/gmanager_client.c:43:6:

error: a label can only be part of a statement and a declaration is not a statement...

View 4 Replies View Related

C :: How To Pass 2 Array Pointers To A Function

Aug 4, 2013

How would I pass let say 2 array pointers to a function X , allocate memory for them in X , fill them with values and get them back in my main function without creating a structure.

example:

Code:

void X(int *a, int*b){
a= malloc ...
b = malloc ...
// fill a and b
return them back to the main function
}
void main(){

[Code]...

View 3 Replies View Related

C :: Basic Array Pointers Program

Feb 4, 2014

Code:

#include <stdio.h>
void Swap(int *x, int *y);
int *Largest(int *array, int size);
int main()
{
int a, b, i;
int c[10];
int maxaddress;
}

[code]...

My swap function works fine, but I am trying to find the ADDRESS of the largest element in my array and I am getting an error using gcc on my "return &largest;" and my printf line in my main function.How can I fix this and return the address of the largest?

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved