vector of substrings

This is a discussion on vector of substrings within the C++ Programming forums, part of the General Programming Boards category; Edited! Thanks! I thought at least I should not post *BAD* examples for new programmers...

  1. #31
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Edited! Thanks! I thought at least I should not post *BAD* examples for new programmers

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,014
    Code:
    #include <iostream>
    
    const char fontMap[][5][4] = 
    {
    	{
    		"XXX",
    		"X X",
    		"X X",
    		"X X",
    		"XXX"
    	},
    	{
    		" X ",
    		"XX ",
    		" X ",
    		" X ",
    		"XXX"
    	},
    	{
    		"XXX",
    		"  X",
    		"XXX",
    		"X  ",
    		"XXX"
    	},
    	{
    		"XXX",
    		"  X",
    		"XXX",
    		"  X",
    		"XXX"
    	},
    	{
    		"X X",
    		"X X",
    		"XXX",
    		"  X",
    		"  X"
    	},
    	{
    		"XXX",
    		"X  ",
    		"XXX",
    		"  X",
    		"XXX"
    	},
    	{
    		"XXX",
    		"X  ",
    		"XXX",
    		"X X",
    		"XXX"
    	},
    	{
    		"XXX",
    		"  X",
    		"  X",
    		"  X",
    		"  X"
    	},
    	{
    		"XXX",
    		"X X",
    		"XXX",
    		"X X",
    		"XXX"
    	},
    	{
    		"XXX",
    		"X X",
    		"XXX",
    		"  X",
    		"XXX",
    	}
    };
    
    const int FONT_HEIGHT = 5;
    
    using std::cout;
    
    int main(int argc, char *argv[])
    {
    	if (argc != 2) 
    	{
    		printf("Usage\n\taa.py <number>\n");
    		return 1;
    	}
    	long number = strtol(argv[1], NULL, 10);
    	if (number == 0 && argv[1][0] != '0')
    	{
    		cout << "Error: Only digits allowed!\n";
    		return 1;
    	}
    	int length = strlen(argv[1]);
    	for (int j = 0; j < FONT_HEIGHT; j++) // For every line of the font array
    	{
    		for (int i = 0; i < length; i++) // For every number of the command argument
    		{
    			int number = argv[1][i] - '0';
    			cout << fontMap[number][j] << " ";
    		}
    		cout << "\n";
    	}
    	return 0;
    }
    Yes, it's longer, but wow is it easier to understand and use!
    Last edited by Elysia; 05-10-2008 at 07:39 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.

  3. #33
    Banned
    Join Date
    Nov 2007
    Posts
    678
    :&#112; pppppppp

    Do you also mean that your version does exactly the same as my version??

  4. #34
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,014
    Yes it does. I took your version and modified it.
    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.

  5. #35
    Banned
    Join Date
    Nov 2007
    Posts
    678
    This is my output, for 5577:
    Code:
    @@@ @@@ @@@ @@@ 
    @   @     @   @ 
    @@@ @@@   @   @ 
      @   @   @   @ 
    @@@ @@@   @   @
    Post your output??

  6. #36
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,014
    That's an entirely different issue. Your code was confusing as it is.
    I'll do a few modifications and you'll see it will work fine.

    123456789:
    Code:
     X  XXX XXX X X XXX XXX XXX XXX XXX
    XX    X   X X X X   X     X X X X X
     X  XXX XXX XXX XXX XXX   X XXX XXX
     X  X     X   X   X X X   X X X   X
    XXX XXX XXX   X XXX XXX   X XXX XXX
    Last edited by Elysia; 05-10-2008 at 07:40 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.

  7. #37
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Honestly yours came out simpler and better, because you arranged the font map better!
    But that was my point, I wanted to make it obfuscated, so that font map does not give away the looks of fonts!

  8. #38
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,014
    Pfft.
    Readability comes before obfuscation =)
    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.

  9. #39
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Oh, and by the way I can change my font style from 'X' to '@' to '#' to 'M' by changing a single char in the code!

    Can you??

  10. #40
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,014
    Yes, using search & replace.
    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.

  11. #41
    Banned
    Join Date
    Nov 2007
    Posts
    678
    How?

  12. #42
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,014
    Search & replace in your IDE. Find X, replace with 'whatever'.
    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.

  13. #43
    Banned
    Join Date
    Nov 2007
    Posts
    678
    You are lucky that there is no other 'X' except in your font map

  14. #44
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,014
    Well, all I do is tell the IDE to search and replace with the selection which is all the map.
    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.

  15. #45
    Banned
    Join Date
    Nov 2007
    Posts
    678
    How about doing this:
    Code:
    555 555 777 777 
    5   5     7   7 
    555 555   7   7 
      5   5   7   7 
    555 555   7   7
    I just had to change:
    Code:
    putchar(fontMap[row][i1]=='0' ? ' ' : number[col]);

Page 3 of 4 FirstFirst 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help, extracting substrings from a string
    By doubty in forum C Programming
    Replies: 1
    Last Post: 06-18-2009, 12:57 AM
  2. Need help on substrings and streams
    By TaiL in forum C++ Programming
    Replies: 2
    Last Post: 10-08-2008, 07:18 PM
  3. Searching for a series of possible substrings inside a string
    By andrew.bolster in forum C Programming
    Replies: 7
    Last Post: 02-10-2008, 02:20 AM
  4. substrings
    By arjunajay in forum C++ Programming
    Replies: 30
    Last Post: 06-10-2005, 10:13 PM
  5. Searching strings - substring's
    By Vber in forum C Programming
    Replies: 4
    Last Post: 02-06-2003, 12:05 PM

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