C/C++ :: Using Pointers For Character Array In For Loop
Nov 3, 2014
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]......
View 7 Replies
Mar 30, 2013
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]...
View 9 Replies
View Related
Apr 14, 2013
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].....
View 2 Replies
View Related
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
Jul 4, 2014
Can we do this :
Code:
char strings[][100]={"ABC","EFG","IJK","LKM"};
char temp[100];
temp=strings[1];
View 3 Replies
View Related
Jul 28, 2014
it will produce the answer above..when user enter a nonnumerical character it will force the user to reenter again
do {
cout<<"Min of the secret number : ";
cin>>min;
}while(cin>>min);
cout<<"Max of the secret number : ";
cin>>max;
this is my coding but it will auto jump out when i enter non-numeric character
View 7 Replies
View Related
Jul 28, 2014
it will produce the answer above..when user enter a nonnumberic character it will force the user to reenter again
do
{
cout<<"Min of the secret number : ";
cin>>min;
}while(cin>>min);
cout<<"Max of the secret number : ";
cin>>max;
this is my coding but it will auto jump out when i enter non-numberic character
View 1 Replies
View Related
Jan 3, 2015
I'm familiar with the concept of int in the for loop. However, I've seen a case where the condition for the for loop is a pointer. How is the pointer used or interpreted in the for loop condition in C or C++.
As an example:
Code:
void printer(char *fmt, ...) {
va_list args;
char *p, *sval;
int ival;
double dval;
va_start(args, fmt);
for(p = fmt; *p; p++) {
if(*p != '%') {
putchar(*p);
continue;
[Code]....
View 3 Replies
View Related
Jun 27, 2013
Set an Array (a[10]) and a Pointer to that array (*pa) and code a loop (for( ; ; loop) that will advance that pointer (*pa) and will set a new content into it with each loop. that means that in the end of the day, my program will automatically set content to each cell of the array by promoting the pointer by 1 and add the sum to that pointer.
When I run the program it prints the address of the cells instead the value of it.
Code:
#include <stdio.h>
void main() {
float a[11], *pa; // Array and ptr set.
int i; // counter for the loop.
pa = a;
for (i=0 ; i<=10 ; i++) // the loop itself.
[Code] .....
View 3 Replies
View Related
Feb 11, 2014
The function uses a "for" loop to print the given character the number of times specified by the integer.
How can I make a for loop to do that?
So.. my code looks like this:
// cpp : Defines the entry point for the console application
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void printMyInteger(int myInteger, char myChar) {
[Code] ....
So.. here is my error:
Error1error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
Error2error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
3IntelliSense: expected an expressiond:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp107Week 6
View 3 Replies
View Related
Feb 4, 2014
I wanted to display the correct output by using a for loop at the end of my code, but for some reason it's not working correctly.
#include <iostream>
using namespace std;
int main() {
int* ipArray[3];
for(int i = 0; i < 3; i++) {
ipArray[i] = new int [5];
[Code] .....
What I wanted to do is pretty much match my 1st out put like 0 1 2 3 4 but my 2nd output only outputs 24's and I don't know why
View 11 Replies
View Related
Jun 14, 2013
The program should store a character array in reverse order then display the reversed array. I have also included in the code that will display the actual characters into the array as it loops through. So I know the characters are being stored, but why doesn't it display the entire string when I call it?
Code:
#include<stdio.h>
int main(){
char str[50];
char rev[50];
printf("Enter Desired Text: ");
scanf ("%[^
[Code] ....
Is it just my compiler?
View 5 Replies
View Related
Apr 16, 2014
I am currently having an issue with validating user input for a state abbreviation. I have an array where a list of abbreviations is stored to use as a comparison for whatever the user inputs. I have been able to get the list loaded properly but whenever i go to compare, it always comes back as true even if it isn't. Here is some relevant code:
static char stateTable[STATE_TABLE_SIZE][STATE_SIZE];
int main() {
char buffer[40], *testCustName[40], testState[5], testCode;
buffer[0] = '