3

I created a C function in test.c

#include <stdio.h>


int Test()
{
    FILE * fp = fopen("C:\\workspace\\test.txt", "rw");
    fprintf(fp, "test hello world");
    fclose(fp);
    return 10;
}

And I defined a state in stateflow of simulink. I used

en: Test();

I specified the file in both Tools->Open Simulation Target->Custom Code->Include List of additional and Include Custom C Code in generated (using absolute path and file name) When I tried to run the model, I got parser error: en: Test(); ^ Function named 'Test' is not a Stateflow Function.

What should I do?

user1192878
  • 704
  • 1
  • 10
  • 20

2 Answers2

4

Got it done by my own. In the "Include Custom C Code in generated:"->Header file tab, I should specify my header file as

#include "test.h"

instead of

test.h

And c file should be specified in "Include list of additional"->Source files as

test.c
Praetorian
  • 106,671
  • 19
  • 240
  • 328
user1192878
  • 704
  • 1
  • 10
  • 20
3

Adding reference to an online example for adding custom C code to Stateflow that will help other users who run into similar issues: http://www.mathworks.com/support/solutions/en/data/1-1727V/

Siddharth
  • 31
  • 1