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).
I need to calculate how often each letter appears in a text file from a function that is called from main() with an array of pointers to char and how many pointers there are in the array. The code i have so far is:
I get no errors and it runs but it gives me the wrong output. I know my array is correct because when i print it in main() it is correct but each letter is incorrectly counted. When i give it the input .txt file of:
This is one line of a string This is another This is the third one Wow heres another one It counts a as 8 b as 1 c as 3 etc.
I have hand traced it and cant figure out why it isnt giving me correct values
how could i allocate memory is only needed for every string(as long as it is)? Cause in my code i allocate memory for 100 strings and for 10 characters for every string.
I have wrote the code below that compares to strings and sees if they are equals doesn't matter the order of the words . In the question we where asked not to use any library functions like the string functions in <string.h> and we have to do that all with pointers . I debugged my code and for some reason the first loop in the function keeps looping ...
#include<stdio.h> int IsEqual(char* str1,char* str2); #define SIZE 20 void main() { char str1[SIZE]="my name is monaya",str2[SIZE]="name monaya is my"; if (IsEqual(str1,str2))
This is my program and i dont know what is the better strategy to display the output perfectly align with the title, when i input a long variable or short the variable move and it does not align with its title. what can i do.
#include <iostream> #include <string> #include <string.h> #include <cstdlib> #include <cstring> #include <iomanip> using namespace std; struct book {
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
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.
1. I finished reading a beginning C book, and in the section about arrays, it says that one string can fit in a character array (char arrayname[]) but there cannot be a string array (string arrayname[]) that have multiple strings. Is
Code: string arrayname[4] = {"one", "two", "three"}; not valid?
My compiler lets me run it and it works, but why is the book saying it's wrong?
2. I know you can represent multiple strings in a character array by:
because [10][4] indicates that there should be four newarrays created with a max of 10 characters each, but is
Code: string multiplestrings[10][4] = ("i love you", "hello come to me", "i don't get C"; "hello world", "what are arrays"; "i am happy", "I am learning how to code"); valid?
Does multiplestrings[10][4] basically create 4 string arrays that have a maximum of 10 different strings within each string array?
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):
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:
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.
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.
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.
#include<iostream>; using namespace std; int strlen(char []); void strcat(char S1[], char S2[], int size_1, int size_2); const int SIZE = 100; const int MAX = 100;
[Code]...
i have been trying to do a function that unites strings entered by user, i need to do this without any other libraries but i keep getting an output of the first word and dots.
I was very much confused with managing the 3d arrays. Other than initialising it is tough for me to input the data into the 3d array at runtime. I have tried the every possible method i know untill now but i can't successfully input and output the data.
I have written a code by declaring the 3d array of char s[5][2][20] in main and passing it's base address into another function, lets say input(char (*p)[2][20],int ,int ,int). I have passed the 3 dimensions in declaration 5,2,20 to the input function i have used these 3 values as the subscript for the pointer p and tried to input the data. But i wasn't successful.
How to input the strings into the 3d array.
My preferences were:
1.The change of subscript value should take place in loop(eg:for). 2.Which indexes should be used for inputing the data through pointer. 3.Use either "scanf" or "gets" function to inputs the data and print using "printf" or puts.
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.
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.
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.
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)
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:
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(){