Help with C.

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
User avatar
bashcommando
Level 1
Level 1
Posts: 20
Joined: Mon Aug 26, 2013 3:24 pm

Help with C.

Post by bashcommando »

I was compiling a C script and this happened:

Code: Select all

Kernel.c: In function ‘main’:
Kernel.c:9:9: error: ‘true’ undeclared (first use in this function)
Kernel.c:9:9: note: each undeclared identifier is reported only once for each function it appears in
Kernel.c:12:8: warning: assignment makes integer from pointer without a cast [enabled by default]
Kernel.c:17:13: warning: assignment makes integer from pointer without a cast [enabled by default]
Kernel.c:20:13: warning: assignment makes integer from pointer without a cast [enabled by default]
Kernel.c:23:13: warning: assignment makes integer from pointer without a cast [enabled by default]
Kernel.c:36:13: warning: assignment makes integer from pointer without a cast [enabled by default]
Kernel.c:39:13: warning: assignment makes integer from pointer without a cast [enabled by default]
Kernel.c:42:13: warning: assignment makes integer from pointer without a cast [enabled by default]
Kernel.c:45:13: warning: assignment makes integer from pointer without a cast [enabled by default]
Here is my code:

Code: Select all

#include <stdio.h>

int main()
{
	int c;
	int docname;
	printf("MyOS V1.0/n");
	printf("This is open-source and for you to use freely!/n");
	while (true) {
		printf("Command:");
		scanf("%d", &c);
		if (c="loadc") {
			printf("Filename:");
			scanf("%d", &docname);
			// Add code here
		}
		else if (c="loadlua") {
			printf("loadlua is not finished yet/n");
		}
		else if (c="math") {
			printf("math is not finished yet/n");
		}
		else if (c="?") {
			printf("Commands:/n");
			printf("======================================/n");
			printf("loadc - loads a C file/n");
			printf("loadlua - loads a Lua file(incomplete)/n");
			printf("math - does math(incomplete)/n");
			printf("? - Displays this/n");
			printf("read - Displays a text file(incomplete)/n");
			printf("clear - Clears the screen/n");
			printf("sleep - Halts everything until you return(incomplete)/n");
			printf("======================================/n");
			printf("End Help/n");
		}
		else if (c="") {
			printf("Cannot execute a null command/n");
		}
		else if (c="read") {
			printf("read is not finished yet/n");
		}
		else if (c="sleep") {
			printf("sleep is not finished yet/n");
		}
		else if (c="clear") {
			clrscr();
		}
		else {
			printf("The command was not found/n");
		}
	}
}
What happened?
If its linux, its SHOULD be open-source!
MBS
Level 1
Level 1
Posts: 3
Joined: Mon Sep 02, 2013 2:20 pm

Re: Help with C.

Post by MBS »

I'm not a C guru but shouldn't you have set the varable c as

Code: Select all

char c[#] //where # = size of string +1
and you cant, might be wrong, compare strings directly like you can in basic.

Code: Select all

 if a$="you rock" then print "thanks your awesome too"
im sure you have to use a function call strncmp() or strcmp() to compare strings to strings....c doesnt have a proper string varable type

something like

Code: Select all

if( strcmp( c, "load" ) )
{
   printf( "Load function called\n");
};
i think it's been 15 since i did any c coding so i might be chatting rubbish
User avatar
z1p101
Level 1
Level 1
Posts: 31
Joined: Tue Jul 24, 2012 7:29 pm

Re: Help with C.

Post by z1p101 »

My basic C coding is rusty but it looks like you are declaring variable c as data type int and using/comparing it to data type string or char array.

Dumb it down and change all your "strings" to numbers. for example

Code: Select all

printf("Command: must be a nuber :");
      scanf("%d", &c);
.....
if (c=1) {
         printf("Filename: not done yet");
         //scanf("%d", &docname);
         // Add code here
      }


if (c=2) {
         printf("loadlua is not finished yet/n");
     }

.......
JosephM
Level 6
Level 6
Posts: 1169
Joined: Sun May 26, 2013 6:25 pm

Re: Help with C.

Post by JosephM »

I am a newb to C but shouldn't all of your comparison operations (if/else) be using the comparison operator "==" not the assignment operator "="? I also believe to use "true" in C you have to #include<stdbool.h> or just use "1" for true and "0" for false.
When I give opinions, they are my own. Not necessarily those of any other Linux Mint developer or the Linux Mint project as a whole.
User avatar
bashcommando
Level 1
Level 1
Posts: 20
Joined: Mon Aug 26, 2013 3:24 pm

Re: Help with C.

Post by bashcommando »

z1p101 wrote:My basic C coding is rusty but it looks like you are declaring variable c as data type int and using/comparing it to data type string or char array.

Dumb it down and change all your "strings" to numbers. for example

Code: Select all

printf("Command: must be a nuber :");
      scanf("%d", &c);
.....
if (c=1) {
         printf("Filename: not done yet");
         //scanf("%d", &docname);
         // Add code here
      }


if (c=2) {
         printf("loadlua is not finished yet/n");
     }

.......
Umm... Not exactly what im looking for but its going to be a system like DOS almost.
If its linux, its SHOULD be open-source!
Post Reply

Return to “Software & Applications”