Thread: I need help to run sample code from internet

  1. #1
    Registered User
    Join Date
    May 2017
    Posts
    119

    I need help to run sample code from internet

    I am trying to run sample code on my PC

    I have following three files taskrunner.h task.h runtask.c

    Code:
    #ifndef TASKRUNNER_H#define TASKRUNNER_H
    int taskrunner(Task * TaskList, unsigned int listLen);
    
    
    #endif	// TASKRUNNER_H

    Code:
    #ifndef TASK_H#define TASK_H
    
    
    typedef int (*task_init)(int);
    typedef int (*task_func)(int);
    
    
    typedef struct {
    	char taskName[20];
    	// task_init init;
    	// task_func func;
    	int *	runNow;
    } Task;
    
    
    #endif	//TASK_H
    Code:
     #include "stdio.h"#include "../include/errors.h"
    #include "../include/tasks.h"
    #include "../include/taskrunner.h"
    
    
    int doNow, doLater;
    
    
    int taskrunner(Task * TaskList, unsigned int listLen)
    {
    	int iter;
    
    
    	printf("Running Tasks, %d\n", listLen);
    	for(iter = 0; iter < listLen; iter++)
    	{
    		if( 0 == *TaskList[iter].runNow)
    		{
    			printf("%s, %d\n", TaskList[iter].taskName, *TaskList[iter].runNow);
    		}
    	}
    	return(iter);
    }
    
    
    Task tasks[] = {
    	{"First_Task", &doNow},
    	{"Second_Task", &doLater},
    	{"Third_Task", &doNow},
    };
    
    
    #define NUM_TASKS sizeof(tasks)/sizeof(Task)
    
    
    int runAllTasks(void)
    {
    	int Error;
    	Error = 0;
    	doNow = 0;
    	doLater = 0;
    	while(0 == Error)
    	{
    		Error = taskrunner(tasks, NUM_TASKS);
    		if(doLater == 0)
    			Error = 0;
    		doLater = 1;
    	}
    	return(Error);
    }
    
    
    int main()
    {
    	int Error;
    	printf("Hello world\n");
    	/* Initialize task list */
    	/* Run the task list using the given tasks */
    	printf("Final task result = %d\n", runAllTasks());
    	return(0);
    }
    I get following error message any help how to remove it

    C:\Users\Vij\Downloads\TaskTurner-master\TaskTurner-master\tasker\src>gcc -o runtask runtask.c
    In file included from runtask.c:2:0:
    c:\mingw\include\errors.h:158:1: error: unknown type name 'DWORD'
    DWORD WINAPI AMGetErrorTextA(HRESULT,CHAR*,DWORD);
    ^~~~~
    c:\mingw\include\errors.h:158:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'AMGetErrorTextA'
    DWORD WINAPI AMGetErrorTextA(HRESULT,CHAR*,DWORD);
    ^~~~~~~~~~~~~~~
    c:\mingw\include\errors.h:159:1: error: unknown type name 'DWORD'
    DWORD WINAPI AMGetErrorTextW(HRESULT,WCHAR*,DWORD);
    ^~~~~
    c:\mingw\include\errors.h:159:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'AMGetErrorTextW'
    DWORD WINAPI AMGetErrorTextW(HRESULT,WCHAR*,DWORD);

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,567
    You probably have to #include <windows.h> in errors.h
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2017
    Posts
    119
    Quote Originally Posted by laserlight View Post
    You probably have to #include <windows.h> in errors.h
    laserlight

    I did changes
    Code:
    #include<stdio.h>
    //#include "../include/errors.h"
    #include<windows.h>
    #include "../include/tasks.h"
    #include "../include/taskrunner.h"
    error

    c:\mingw\include\errors.h:158:1: error: unknown type name 'DWORD'
    DWORD WINAPI AMGetErrorTextA(HRESULT,CHAR*,DWORD);
    ^~~~~
    c:\mingw\include\errors.h:158:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'AMGetErrorTextA'
    DWORD WINAPI AMGetErrorTextA(HRESULT,CHAR*,DWORD);
    ^~~~~~~~~~~~~~~
    c:\mingw\include\errors.h:159:1: error: unknown type name 'DWORD'
    DWORD WINAPI AMGetErrorTextW(HRESULT,WCHAR*,DWORD);
    ^~~~~
    c:\mingw\include\errors.h:159:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'AMGetErrorTextW'
    DWORD WINAPI AMGetErrorTextW(HRESULT,WCHAR*,DWORD);

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,567
    That looks impossible: you commented out the include of errors.h, so how could the compiler still be complaining about its content? It should be complaining about code that depends on what was declared in errors.h, or nothing at all.

    Furthermore, your header files should bd self-contained. Consider:
    Code:
    #ifndef TASKRUNNER_H
    #define TASKRUNNER_H
    int taskrunner(Task * TaskList, unsigned int listLen);
     
     
    #endif  // TASKRUNNER_H
    What's Task? It is undeclared in this header. You should either declare it, or include the header that declares it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    May 2017
    Posts
    119
    Quote Originally Posted by laserlight View Post
    That looks impossible: you commented out the include of errors.h, so how could the compiler still be complaining about its content? It should be complaining about code that depends on what was declared in errors.h, or nothing at all.

    Furthermore, your header files should bd self-contained. Consider:
    Code:
    #ifndef TASKRUNNER_H
    #define TASKRUNNER_H
    int taskrunner(Task * TaskList, unsigned int listLen);
     
     
    #endif  // TASKRUNNER_H
    What's Task? It is undeclared in this header. You should either declare it, or include the header that declares it.
    I am trying to run code given in the example GitHub - EmbeddedApprentice/TaskTurner: A first, very short beginning for the TaskTurner.

    When I unzip folder I get only three file taskrunner.h task.h runtask.c I don't see error.h in folder

    once code will run so I can try to understand what's happening

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,567
    Quote Originally Posted by abhi143
    When I unzip folder I get only three file taskrunner.h task.h runtask.c I don't see error.h in folder
    You're right. Unfortunately, what this means is that the project that you've found has a missing file. You'll have to file a bug report or otherwise contact the maintainer to have it fixed.

    EDIT:
    Then again, it looks like this project was last updated 3 years ago, so it might not be actively maintained. May be worth a try to open an issue (i.e., file a bug report) anyway if you're really so interested in it, but given the quality of the code I'm not sure if it is really worth it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Dec 2017
    Posts
    874
    That code is garbage and unfinished.
    Why are you interested in it?
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

  8. #8
    Registered User
    Join Date
    May 2017
    Posts
    119
    Quote Originally Posted by john.c View Post
    That code is garbage and unfinished.
    Why are you interested in it?
    Okay so I will leave it here

    I was looking some sample to create basic scheduler in c programming.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get the sample code?
    By krishnampkkm in forum C++ Programming
    Replies: 2
    Last Post: 06-19-2009, 04:41 AM
  2. Sample code please help!!!
    By aewing30 in forum C Programming
    Replies: 6
    Last Post: 05-29-2008, 10:51 AM
  3. is this C++ code sample?
    By chico1001 in forum C++ Programming
    Replies: 18
    Last Post: 03-03-2006, 03:05 PM

Tags for this Thread