All your JNI calls are missing the first parameter which should be env, as you're in compiling C code.
If your code was in C++, you could make calls like env->NewStringUTF("xx"). But in C, JNIEnv* isn't an object, hence you have to pass it as first argument, like so: (*env)->NewStringUTF(env, "xx")
As for NULL being undefined, you can solve this by including the header that defines it: #include <stddef.h>
All your JNI calls are missing the first parameter which should be env, as you're in compiling C code.
If your code was in C++, you could make calls like env->NewStringUTF("xx"). But in C, JNIEnv* isn't an object, hence you have to pass it as first argument, like so: (*env)->NewStringUTF(env, "xx")
As for NULL being undefined, you can solve this by including the header that defines it: #include <stddef.h>
The second parameter does not seem to be optional:
jboolean iscopy;
const char *name = (*env)->GetStringUTFChars(string, &iscopy);
Why am I getting undeclared (first use in this function)
'NULL' undeclared...
'NULL' undeclared (first use in this function)
'NRF_SUCCESS' undeclared (first use in this function); did you mean 'EXIT_SUCCESS'?
Videos
'If' block itself is a scope, and you define a scope and the variables are only accessible inside the scope, not outside, and not at the boundary either.
For sure, the c variable should be declared outside the For loop:
Copychar c = ' ';
for ...
The error would occur at following line:
Copy p[i] = c;
It is because c is local scope at the following line:
Copy if (islower(p[i]))
{
char c = (((p[i] - 97) + k) % 26) + 97;
return 0;
}
and
Copy {
char c = (((p[i] - 65) + k) % 26) + 65;
return 0;
}
and
Copy else{
char c = (((p[i] - 65) + k) % 26) + 65;
}
Local scope means that it will be released after exit the }.
Additionally, after first 2 condition of if, else if, there is also return after define value to c. If so, the API will return immediate and c is not used at any line because the assignment p[i] = c; will not execute.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct info
{
char *firstName;
char *lastName;
int PUID;
int age;
};
struct node
{
struct info student;
struct node *next;
};
struct node *root = NULL;
struct node *curr = NULL;
void create_list_node( char fName[30], char lName[30], int id, int ages);
int main()
{
return 0;
}
/*
void create_list_no_nodes()
{
root = (struct node*)malloc(sizeof(struct node));
root-> next = 0;
}
*/
void create_list_node( char fName[30], char lName[30], int id, int ages)
{
free(root);
root = (struct node *) malloc(sizeof(struct node));
root->student.firstName = fname;
root->student.lastName = lname;
root->student.PUID = id;
root->student.age = ages;
root->next = NULL; here is the error:
Lab5_main.c: In function ‘create_list_node’:
Lab5_main.c:54:29: error: ‘fname’ undeclared (first use in this function)
root->student.firstName = fname;
^
Lab5_main.c:54:29: note: each undeclared identifier is reported only once for each function it appears in
Lab5_main.c:55:28: error: ‘lname’ undeclared (first use in this function)
root->student.lastName = lname;
^So i am creating a program that uses a linked list.
This code below compiles and works but i want to change it.
* Example of working code */
int main(){
// Start menu
menu();
return 0;
}
void menu(){
//Create list
node * HEAD = NULL;
HEAD = createLinkedList();
//Print menu, scanf i
int i = 13;
while(i != 0){
printMenu();
scanf("%d", &val);
if ( i == 1)
printList(HEAD);
}}I want to rewrite the code so that the list is created in the "main" function, not the "menu" function. However when I tried to compile the code below i get the error: error: ‘HEAD’ undeclared (first use in this function)
* Example of not working code */
int main(){
//Create list
node * HEAD = NULL;
HEAD = createLinkedList();
// Start menu
menu();
return 0;
}
void menu(){
//Print menu, scanf i
int i = 13;
while(i != 0){
printMenu();
scanf("%d", &val);
if ( i == 1)
printList(HEAD); // ERROR here
}}FILE and NULL are wrongly written (C is case sensitive). fopen line was missing a semicolon.
Code below compiles and runs.
#include <stdio.h>
main(void) {
FILE *file = fopen("words.txt","r");
if(file != NULL) {
char line[128];
while(fgets( line, sizeof line, file) != NULL)
{
fputs ( line, stdout );
}
fclose ( file );
}
}
The following works fine and has been cleaned up with consistent braces and spaces in function calls and definitions and loops/ifs. It also works in C, if that was your intent from the tags, and prints an error and returns 1 if the file cannot be opened.
#include <stdio.h>
#include <errno.h>
int main (void) {
char line[128];
FILE *file = fopen ("words.txt", "r");
if (file != NULL) {
while (fgets (line, sizeof line, file) != NULL) {
fputs (line, stdout);
}
fclose (file);
} else {
fprintf (stderr, "Cannot open 'words.txt', error = %d\n", errno);
return 1;
}
return 0;
}
There's NULL and then there's NUL.
NULL is defined in stddef.h, is used very widely, and is a reference to a null pointer.
NUL is different - it is the first character in the standard ASCII character set, and more importantly, it is not a standard macro. You may have to define it yourself.
To define NUL, do:
#define NUL '\0'
No, that's not standard. Add this at the beginning of your code or just use 0:
#define NUL 0
I infered you're not looking for NULL since you're doing ch == NUL
In various texts it is quite frequent to refer to '\0' as NUL.