Hello strangers,
I'm having an issue coming up with an if() statement to check if a word match the one in the value of a pointer's address.
So far the best I've come up with only matches the first letter of the words, you'll find it in the code below.
Code:
#include"Header.h"
int Colour(struct MyStruct *ArrayPointer, int ArraySize) //ArraySize = 3 for this run.
{
int ColourCount = 0;
for (int i = 0; i < ArraySize; i++)
{
printf("\nShirt %d colour: %s", i + 1, ArrayPointer->ShirtColour);
printf("\nShirt %d colour address: %d", i + 1, &ArrayPointer->ShirtColour);
if (*ArrayPointer->ShirtColour == 'R') // How can I make it check for Red instead of just the first letter?
{
ColourCount++;
}
ArrayPointer++;
}
printf("\n\nColourCount: %d", ColourCount);
_getch();
printf("\n\n//////////////////////////////\n\n");
return ColourCount;
}
/*
In Header.h
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
struct MyStruct
{
int ShirtSize;
char ShirtColour[32];
};
*/
/*
ArrayPointer declaration.
#include"Header.h"
struct MyStruct *Stock(int ArraySize)
{
struct MyStruct *ArrayPointer;
ArrayPointer = malloc(sizeof(*ArrayPointer) * ArraySize);
return ArrayPointer;
}
*/
/*
Call to this function.
Colour(ArrayPointer, ArraySize);
*/
An example run you can see in here:
I want to have an if statement that only accepts "Red" and not the occasional "Ravaged_Anus".
I'm using MVS Express 2013, .c source files, and the C++ compiler.
Thank you for your time.