C :: How To Use Character Pointers Instead Of Arrays
Apr 14, 2013Here is my program to look up words. How do I use character pointers instead of using arrays?
Code:
#include <stdio.h>
struct entry
{
[Code].....
Here is my program to look up words. How do I use character pointers instead of using arrays?
Code:
#include <stdio.h>
struct entry
{
[Code].....
I'm trying to write a function that takes a 32bit address and a data to store at this address.
I'm wanting to take the 32 bit memory address eg 0x12345678 and split it
into 4 x 2 bytes
12, 34, 56, 78
then each of the 4 entries is at most a 256 entry array.eg
FF, FF, FF, FF
So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.
After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.
The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.
It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.
void cpu::store(unsigned int mem_add,unsigned int mem_val) {
int first = (mem_address&4278190080)>>24;
int second = (mem_address&16711680)>>16;
int third = (mem_address&65280)>>8;
int fourth= (mem_address&255);
[Code] .....
A1 has been declared as
int* A1[256] ;
I am able to work with n instances of a structure in one mallocated area, but when I try to do the same thing with just character pointers, I get compiler errors about making integer from pointer without a cast. If I create a structure with just a character pointer in it, it works just fine... I am just not seeing something here!!!
This works:
Code:
#include <stdio.h>
#include <stdlib.h>
int main (void) {
struct items {
unsigned int item_1;
unsigned int item_2;
[Code]...
This DOES NOT work!
Code:
#include <stdio.h>
#include <stdlib.h>
int main (void) {
char * items_ptr = NULL;
unsignedint i = 0;
char * one = "one";
char * two = "two";
[Code]...
I'm taking an intro to programming course and my assignment is to Write a very simple program that uses two for loops and ONLY pointers and pointer arithmetic (NO other variables are allowed) to display a palindrome forward then backward. Declare the palindrome as follows: char str[] = “Straw Warts”; Well my prof never did anything with char arrays and I can't quite fit make the pointers work in the loop. This is my code. It runs how it should, i just can't seem to make a working for loop. It always says that you can compare int and char
#include <iostream>
using namespace std;
int main()
{
[Code]......
I'm trying to create Minesweeper and with 2D Multidimensional character Arrays, It doesnt appear like in a grid format i want it to.
#include<iostream>
#include<conio.h>
#include<string>
#include<cstdlib>
#include<ctime>
[Code]....
According to [URL] ....
" char myword[] = { 'H', 'e', 'l', 'l', 'o', '