[ create a new paste ] login | about

Link: http://codepad.org/bcaAHKmp    [ raw code | output | fork ]

C++, pasted on Dec 6:
#include "pch.h"
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <windows.h>
int main(int argc, char * argv[])
{
	if (argc != 3)
	{
		printf("useage: cfind.ex <text> <filename>\n");
		return -1;
	}

	//Get existing console color
	int OldColor = 15;
	CONSOLE_SCREEN_BUFFER_INFO csbi = { 0 };
	if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
	{
		OldColor = csbi.wAttributes;
	}


	char*pStringToMatch = argv[1];
	char*pFileName = argv[2];

	int len = strlen(pStringToMatch);

	FILE * fp = fopen(pFileName, "r");
	if (NULL == fp)
	{
		printf("failed to open file %s\n", pFileName);
		return -2;
	}

	While (!feof(fp))
	{
		int c = fgetc(fp);
		if (EOF == c) break;

		//Let's find the string to match
		if (c == pStringToMatch[0])
		{
			Char wword[1000];
			int index = 0;
			
			do
			{
				word[index++] = c;
				c = fgetc(fp);
			} while (!feof(fp) && index < len && index < 1000);
			word[index] = '\0';

			if (0 == strcmp(word, pStringToMatch))
			{
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 206);
				printf("%s", word);
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), OldColor);
			}
			else
				printf("%s", word);
		}
		printf("%c", c);
	}
	fclose(fp);
	fp = NULL;
	return 0;
}


Output:
1
2
3
4
5
6
Line 16: error: pch.h: No such file or directory
Line 19: error: stdafx.h: No such file or directory
Line 20: error: windows.h: No such file or directory
In function 'int main(int, char**)':
Line 18: error: 'CONSOLE_SCREEN_BUFFER_INFO' was not declared in this scope
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: