Codeheat icon indicating copy to clipboard operation
Codeheat copied to clipboard

Program in C: Linux Development Basics

Open hpdang opened this issue 1 year ago • 16 comments

This issue can be taken by multiple CodeHeat participants. Anyone can grab this issue at any time. Once you are done, submit the outcome via the form below.

OBJECTIVE

Learn about basic development techniques on the Linux platform by learning how to develop a simple C language program with vim, how to build it with GCC and run it.

REQUIREMENTS

  • Follow the openEuler mirror repository on GitHub indicating your participation
  • Learn basic tools and commands that could be used while software development on Linux platform
  • Follow this instruction
  • Complete all the steps
  • Take a screenshot of the output at the final step (a calculation of cos and sin value)

EXPECTED OUTCOME

  • Learn how to use basic tools and command lines
  • Successfully build and run a simple program on Linux platform

HOW TO SUBMIT YOUR WORK

  • Submit your screenshot here

QUESTIONS

  • If you have any questions, please comment on this issue directly, or reach out to us at https://gitter.im/fossasia/fossasia
  • If you identify any problem while working on this issue, take up a related task to file a bug report

hpdang avatar Dec 19 '23 11:12 hpdang

Hi, when working on this issue, I got a few warnings and errors when compiling the 4 C files at the end of Step 3, as shown in the picture below. I fixed them on my end and can share my code if needed.

Errors

MattXLei avatar Dec 20 '23 16:12 MattXLei

Hi, when working on this issue, I got a few warnings and errors when compiling the 4 C files at the end of Step 3, as shown in the picture below. I fixed them on my end and can share my code if needed. Errors

I think this issue is fixed now. This is the code on my end :).

Screenshot_20231220_225501

Even so, I don't think the function cos_value should be header guarded with SIN_VALUE_H

Labnann avatar Dec 20 '23 17:12 Labnann

Yeah, one of the changes I made was replacing all the SIN_VALUE_H in cos_value.h with COS_VALUE_H, and the code worked as a result.

MattXLei avatar Dec 20 '23 18:12 MattXLei

@hpdang Do we need to only submit the form or need to make the PR?

ankur0904 avatar Dec 21 '23 18:12 ankur0904

@ankur0904 only submit the form, thanks!

hpdang avatar Dec 21 '23 18:12 hpdang

@hpdang Thanks!

ankur0904 avatar Dec 22 '23 03:12 ankur0904

@hpdang

The code provided in the zip file has the following files-

  1. cos_value.c
  2. cos_value.h
  3. hello.c
  4. main.c
  5. sin_value.c
  6. sin_value.h

And the main.c code looks like that

#include <stdio.h>
#include "sin_value.h"
#include "cos_value.h"

#define pi 3.14159

char name[255];
float angle;

int main(void)
{
    printf("\n\nPlease input your name: ");
    scanf("%s", &name);
    printf("\nPlease enter the degree angle (ex> 90): ");
    scanf("%f", &angle);
    printf("\nInput angle: %5.2f", angle);
    hello(name);           //// <---------------- ////
    sin_value(angle);
    cos_value(angle);
    return 0;
}

But in the main.c, we are calling the hello function with the name argument, but we have not included the name function like sin_value, cos_value in main.c file so when we compile these files we get the warning like this

main.c:17:5: warning: implicit declaration of function ‘hello’; did you mean ‘ftello’? [-Wimplicit-function-declaration]
   17 |     hello(name);
      |     ^~~~~
      |     ftello

Solution to this problem: Create a new file hello.h with the following code

#ifndef HELLO_H
#define HELLO_H

void hello(char* name);

#endif

And in main.c

#include <stdio.h>
#include "sin_value.h"
#include "cos_value.h"
#include "hello.h"        // <---------- Add the code // 

#define pi 3.14159

...

After that, the code is compiled and consistent with the remaining files sin_value.c, cos_value.c.

ankur0904 avatar Dec 22 '23 04:12 ankur0904

If the issue is valid I am happy to submit a PR

ankur0904 avatar Dec 22 '23 04:12 ankur0904

@ankur0904 yes, please feel free to submit a PR at the same time you can take up another task to file a report.

hpdang avatar Dec 23 '23 08:12 hpdang

@hpdang I have noticed that the C program files are zipped under the tar file here. So I am confused how to make changes in the file. Meanwhile, I will look at another task

Thanks

ankur0904 avatar Dec 23 '23 16:12 ankur0904

@hpdang I have noticed that the C program files are zipped under the tar file here. So I am confused how to make changes in the file. Meanwhile, I will look at another task

Thanks

Opening a issue there may be a good idea.

Labnann avatar Dec 23 '23 16:12 Labnann

Perhaps the bug in awsome_codes.tar.gz is an exercise for you to do Identify an issue and file a bug report on openEuler?

hongquan avatar Dec 24 '23 10:12 hongquan

Done this issue succesfully, no issues ran in while i was doing it in AWS Redhat based Linux VM

image image

varanasiroshan2001 avatar Jan 04 '24 07:01 varanasiroshan2001

hi, I am unable to run the tar files on macbook, can anyone please help . Thanks! Screenshot 2024-01-08 at 12 26 04 AM

Satarupa22-SD avatar Jan 07 '24 19:01 Satarupa22-SD

Hi, when working on this issue, I got a few warnings and errors when compiling the 4 C files at the end of Step 3, as shown in the picture below. I fixed them on my end and can share my code if needed.

Errors

hi, i got the following issues while working, can you please help curl: (6) Could not resolve host: s Warning: Binary output can mess up your terminal. Use "--output -" to tell Warning: curl to output it to your terminal anyway, or consider "--output Warning: <FILE>" to save to a file.

Satarupa22-SD avatar Jan 07 '24 19:01 Satarupa22-SD

hey @hpdang !, can i work on issue. I am eager to learn linux

Pdahiya5033 avatar Feb 22 '24 16:02 Pdahiya5033