Thread: If statement to check matching word to pointer's address value

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    16

    If statement to check matching word to pointer's address value

    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:
    If statement to check matching word to pointer's address value-namnl-s-png

    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.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Lookup strcmp()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2015
    Posts
    16
    Yeah, works perfect.
    Thanks.

  4. #4
    Registered User
    Join Date
    Jun 2014
    Posts
    79
    You know, I would't appreciate inccurring in any occasional ravaged anus as well. I think it's quite a widespread attitude, even though exceptions are a possibility.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Okey dokey. LOL.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Valid Email address check.
    By ariella in forum C Programming
    Replies: 9
    Last Post: 07-16-2013, 09:17 AM
  2. Returning Address with Return Statement?
    By Waleed Mujeeb in forum C++ Programming
    Replies: 5
    Last Post: 03-23-2012, 05:47 AM
  3. Check for validity of IP address
    By krishnampkkm in forum Linux Programming
    Replies: 1
    Last Post: 03-25-2010, 05:38 AM
  4. IP address range matching
    By Thantos in forum Tech Board
    Replies: 2
    Last Post: 07-16-2009, 04:28 PM
  5. Block address from word address
    By xddxogm3 in forum Tech Board
    Replies: 0
    Last Post: 04-25-2007, 09:02 PM