Thread: help with passing values to a string?

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You really need to work on the indentation. It's difficult to read.
    You need to start using proper variable names, n & m means nothing to me.
    And for the love of the gods, do not use implicit main: http://cpwiki.sourceforge.net/Implicit_main

    This is how a proper indented code should look like:
    (This is an old code of yours, btw.)
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <windows.h>
    #include <stdlib.h>
    
    int main()
    {
    	char input1[100], input2[100];
    	char *p,*q; // Don't need these
    	char checker[100]; 
    	int i,j,n,m; // n & m are very poor variable names
    
    	printf("Please enter a string : ");
    
    	fgets(input1, 100, stdin); // 100 should be sizeof(input1) instead
    
    	printf("Please enter the code : ");
    
    	fgets(input2, 100, stdin);n // Same as first fgets
    
    
    
    	// Unnecessary
    	p = input1;
    	q = checker;
    
    	// Use better variable names
    	n = strlen(input1);
    	m = strlen(input2);
    
    	// Causes bug
    	m = m-1;
    	n = n-1;
    
    	for(i=0;i<n;i++) // Use better variable names!
    	{
    		for(j=0;j<m;j++) // Use better variable names!
    		{
    			checker[j] = input1[i+j];
    		}
    		printf("&#37;s\n%s\n",checker,input2);
    		if (strcmp(checker,input2) == 0)
    			printf("Matched at %d\n", i+1);
    
    	}                             
    
    	system("pause");
    }
    Last edited by Elysia; 10-04-2008 at 04:20 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  2. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 09:37 PM