Xcode for C Implementation - Random Generator - Environment Problems - c

When you have a few files (see below), how do you get them all working inside Xcode for a C implementation?
These are the files that I’ve been given for this project:
pcg_basic.c
pcg_basic.h
pcg32-demo.c
Project guidelines:
http://www.pcg-random.org/using-pcg-c-basic.html
I am also unclear what should be copied to the main.c file. Can't get a grasp on this.
Apparently you also need to link the code with the pcg_basic.o.
(not sure how to do that, either)
I know the code does work because it was developed by an expert in this space. But everything I try in Xcode ("fails to build"), so I presume it must be the way I've set things up.
What am I doing wrong?
*Student here. I am totally new to programming. Thanks!
error snippet 1
error snippet 2
CODE
/*
* PCG Random Number Generation for C.
* For additional information about the PCG random number generation scheme,
* including its license and other licensing options, visit
* http://www.pcg-random.org
*/
/*
* This file was mechanically generated from tests/check-pcg32.c
*/
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
#include "pcg_basic.h" <---pcg_basic.h not found

To setup:
in Xcode <File/New/Project...>
choose macOS template tab
from there choose Command Line Tool
in the Wizard choose C as language
Drag & drop your files (pcg_basic.h, pcg_basic.c, pcg32-demo.c) to the Xcode project navigator on the left where main.c resides. A dialog appears: make sure to check Copy items if needed. Then delete main.c in Xcode.
The program builds and runs then.
Demo

Related

Need help in working with cs50 library, in window device

I'm using visual studio code, in window 10 device, and live in a area where internet accessibility is not good.
I have completed of lecturers of first week of cs50x.
Had extracted cs50.h and cs50.c and copy them to C:\msys64\mingw64\include\
Now after running the code, I'm getting undefined reference to 'get_int' and Id returned 1 exit status.
After going through some online solutions, I get this
In your source code, change #include <cs50.h> to #include <cs50.c>
But I'm not finding any <cs50.h> in cs50.c source file instead it has "cs50.h"
I'm not able to understand
How to link cs50 when compiling your code with clang, by using -lcs50

Program builds sucessfully but netbeans shows errors in the includes

I have this program it builds but shows some errors in the includes
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
/** These two files are necessary for calling CTOS API **/
#include <ctosapi.h>
/**
** The main entry of the terminal application
**/
int main(int argc,char *argv[])
{
BYTE key;
// TODO: Add your program here //
CTOS_LCDTClearDisplay();
CTOS_LCDTPrintXY(1, 1, "Hello");
CTOS_KBDGet(&key);
exit(0);
}
here's the print of it:
print of netbeans window
Edited:
here's the error:
Cannot find include file <stdlib.h>.
I think I found the problem but how do I solve this
has u can see in the image the system directories that look for includes are wrong because they have "/gneaubi" twice, the question is how do I change this
It seems that problem is coming from Netbeans IDE.
I would suggest to follow this once and check if the problem is rectified.
Right-click your project and go to properties.
In the properties, click run and change the console type to standard output.
P.S: Please provide proper info about the error by hovering mouse on error ballon. Given info is not sufficient currently.

Unable to find sys/fdio.h (floppy disk control operations) on Solaris machine 5.11

I am compiling my application code on Solaris 5.11, Code is written in C.In the application code I used "fdio" related code. The Solaris box do not have that . How to get the sys/fdio package.
#include <stdio.h>
#include <sys/fdio.h>
int main()
{
printf("Hello World");
}
"test1.c", line 2: cannot find include file:
The file is no longer available in Solaris 11. Here is a copy that will help you compile your code. Drop it in /usr/include/sys It is opensource so there should be a few copies out there.

I have 2 issues with includes

I am programming in CCS (based on Eclipse) to learn to use microcontrollers.
I'm having some problems with includes.
I have 4 files:
GPIO.h - macros and prototypes of GPIO functions
GPIO.c - implementation of GPIO functions declared in GPIO.h
main.c - main program
util.h - macros and typedefs essential to all other files
In each of the programs put the includes, I ctrl + c / ctrl + v of my code:
I really try with " ", I would like to make my code run, it would be rewarding.
GPIO.h - #include "util.h"
GPIO.c - #include "GPIO.h"
main.c - #include "GPIO.c"
util.h - (no includes)
As in eclipse all files are placed in the project folder. Already checked manually by accessing the folder, and they are there.
When I compile and run, there are 2 errors referring to include:
"../GPIO.c", Line 9: fatal error # 1965: Can not open source file "GPIO.h"
"../main.c", Line 1: fatal error # 1965: Can not open source file "GPIO.c"
I do not understand what's wrong!
I made the edit so that people understand that even with "" the error continues (# mame98). I made it clear that I am using the CCS IDE based on Eclipse and now my suspicion is with the operating system. I will have the opportunity to test on Windows only now.
You should only include H files as Eugene Sh. Points out... Also, use #include "util.h" and #include "gpio.h" as they are local files and they are not in the default search path of your compiler. If you want to include 'global' headers (which are in the search path) you have to use #include <file.h>.
Maybe also note, that it is possible to add your local folder to the search path with using the -I. option for GCC (should work with other compilers too).
For more infos about the search path, see here.
<> is for libraries like #include <stdio.h>
"" is used for your own files #include "GPIO.h"
Be careful including .c! If GPIO.h is included in GPIO.c, too, you could get errors..(multiple inclusion protection is useful here!)

Eclipse project cannot include tchar.h

I am trying to build an lzmat_lib compression library using Eclipse with Cygwin gcc. I downloaded the library from the link http://www.matcode.com/lzmat_lib.zip. The file has the following include files:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <tchar.h>
#include "lzmat.h"
It cannot find the tchar.h header file. I do not understand how to add this header file. Please suggest a solution.
Your options are to install a Windows development environment, like Visual Studio or mingw along with the Windows SDK, or to port the code to your cygwin (posix) environment.
To port the code, you'd just do this:
Remove #include <tchar.h>.
Search and replace _TCHAR to char.
Search the file for all strings beginning with _t and remove that prefix. E.g., _tfopen becomes just fopen. _tprintf becomes printf.
Search for the text _T and remove it. You could also remove the extra parentheses that will then surround your string.
Deal with any other issues as they come up by removing the dependency on tchar.h and using a standard function instead.

Resources