what is wrong

This is a discussion on what is wrong within the C Programming forums, part of the General Programming Boards category; a) Write a program that will determine who the killer is, by matching this fragment to the DNA of the ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    7

    what is wrong

    a) Write a program that will determine who the killer is, by matching this fragment to the DNA of the Suspects. Note that this fragment has to match perfectly with a part of the DNA of the suspect.

    fragment is GCGCA
    suspect DNA is which ever string suspect array is equal to
    Code:
    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    
    char suspect(int);
    int main()
    {
    	char suspect[i][17];
    	int i=0;
    	printf("the suspect that comitted the crime is %s",suspect[i]);
    }
    char suspect(int i)
    {
    	suspect[1]="ATTCGCTTATTCCGAC";
        suspect[2]="AAGCGCTAACCGCTAG";
    	suspect[3]="CAGCGCAAACGCCGTT";
    	suspect[4]="GCGCTCAAAGGCTTAA";
    	if(suspect[i]=="GCGCA")
    	{
    	return(i);
    	}
    }
    i get the error
    error C2109: subscript requires array or pointer type
    where ever suspect is

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You should look at the functions in string.h, especially the ones that search inside strings.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    You need to allocate memory for suspect[][17].

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    The variable 'suspect' and the function 'suspect' can't have the same name.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    Oh yeah. That too. (doh!) I should have spotted that also.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    Not working
    Try to avoid creating new threads which are basically a continuation of the previous question.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21