Home » Compare a pointer to an integer in C [closed]

Compare a pointer to an integer in C [closed]


Here’s what I think you meant to post, it still doesn’t compile though, since you can’t compare a pointer to a char

 *Description: Construction of a social network

#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#define SIZE 30
#define PEOPLE_SIZE 20

struct people   
    char name[SIZE];
    int age;
    char gender[SIZE];
    int idnumber;
    struct friendlist *friends;

typedef struct friendlist
    int friendsname[PEOPLE_SIZE];
    struct friendlist *next;
    struct people *person;
} node_t;

void scan_friends(FILE *input2, node_t *pt)
    char *friend_name;
    fscanf(input2,"%s", &pt->friendsname);

void  print_friends(node_t pt)
    printf("%s ", pt.friendsname);

void print_list (node_t *pt)
    if (pt==NULL)
        printf("The list is emptyn");
    {                 // traversing the list
        while (pt!=NULL)
            while (pt != '*')

int main(void)
    int choice=0;
    FILE *input; //pointer to people.dat

    FILE *input_friends;
    int i=0;
    struct people people[SIZE];
    struct friendlist friendlist[PEOPLE_SIZE];
    node_t *headp, *temp, *current=NULL;
    char user_name[SIZE];
    int user;

    input_friends=fopen("friends.dat", "r"); //opens friends file

        // create a new list element
        temp = (node_t *)malloc(sizeof(node_t));  // memory
        scan_friends(input_friends, temp);    // initialization of element 
        temp->next=NULL;     // setting pointer to null.

        if (current==NULL)
            headp=temp;  // setting the head of the list
            current->next=temp;   // else connecting to previous
        current=temp;   // updating the current element

        i++;   // count number of elements added


My edits have brought it down to only one compile error that you need to sort out yourself. Its on the line 47:

while (pt != '*')

This is certainly not what you want to do.

What do you want to compare to the asterisk? The name?

Consider something like

while (pt->person->name != '*')

Note that this still won’t work because you’ll be comparing a char array with a single char. But this should move you in the direction you want to go, depending on what you want to compare the asterisk to. Note that this is how you access members of a structure which you have a pointer to.

Anything else is just the basics of structs and how to access their members.

Related Solutions

StringBuilder delete methods [closed]

I'd say this is fine. The intent is different. Lets try this for example: String builder sb = new StringBuilder(); sb.append("hello").append("hello"); sb.delete(0,5); sb.toString(); It prints "hello". Had you read the documentation, you'd see that the end is...

How to get specific element from array of type any in swift?

You should not be using JSONSerializer in Swift. A better option is a JSONDecoder. JSONDecoder will allow you to establish and preserve the type information for the data you've decoded. Here is an Playground example of how you would use JSONDecoder to handle...

How to make RecyclerView behave like Paragraph?

The answer is FlexBoxLayoutManager you can use it with RecyclerView put implementation 'com.google.android:flexbox:1.0.0' in your gradle file. Now setting up RecyclerView layout, <?xml version="1.0" encoding="utf-8"?> <RelativeLayout...

Piping commands after a piped xargs

You are almost there. In your last command, you can use -I to do the ls correctly -I replace-str Replace occurrences of replace-str in the initial-arguments with names read from standard input.  Also, unquoted blanks do not terminate input items; instead the...

create arrow using css

Try to use Font awsome LINK HTML: <i class="fa fa-arrow-right"></i> fa-arrow-right Yes, there are several ways of doing this. 1. With an image First of all, in order to do what you've suggested, you can indeed use an image - but instead of coloring...

accessing values structure within structure? [closed]

Just create an object of emp1 inside your main, and give it a value like below and it should be ok emp1 emp; emp.number.number1=3; //printf then with emp.number.number1 😉 You are accessing the value "number1" like emp1.number.number1 but here "emp" data type...

What’s wrong with this way to add rows to dataframe?

Try: data <- data.frame(A= character(0), B= character(0), stringsAsFactors=FALSE) data[1, ] <- c("AA", "BB") In your example, A and B are factors. I would suggest a different approach from the other answers. If A and B are something like names or ID...

Panagram python code [closed]

import string def isPanagram(sentence): alphabet = string.lowercase[:26] # list of letters a-z return all(letter in sentence.lower() for letter in alphabet) The function all will return true if all elements in a list are true The list comprehension inside goes...

VB Code explanation? [closed]

Declare a student name variable that we will call studentname as a string. Think of variables as you would do x and y in an algebraic equation. They are simply names for things of a particular type. In a maths equation x and y are numbers. A string is a...

remove null items from a multidimensional array in C#

Are your null objects always at the end of the multidimentional array? If so use something like this to remove the null items: private static void ReDimMultiObjects(ref object[,] arr, int length) { object[,] arrTemp = new object[length, 3];//New number of...

Check if string contains only one type of letter C# [closed]

Try this: private bool ContainsOnlyOneLetter(string String) { if(String.Length == 0) { return true; } for(int i = 0; i < String.Length;i++) { if(String.Substring(i,1) != String.Substring(0,1)) { return false; } } return true; } And you can use the function...

Couldn’t understand this SWIFT Fucntion [closed]

You're getting 120 because you're asking the tuple for the sum value twice. The tuple passed back is (min: Int, max: Int, sum: Int). In this case, sum is also index number 2 (min is index zero, max is index one). So in this case statistics.sum == statistics.2...

C++ Cli code stucked [closed]

The code you provided does not work on any numbers. The only thing it does is construct some SQL query check its result During the SQL-query-construction, the code does not assume any "numbers" to be provided. It actually uses a variable called...