.
I understand
Anonymous
Allocate next as follows
Anonymous
Uhhhh
Anonymous
ll_a->next = malloc(sizeof ll_a);
Jaaa
Explain
Without pointers 🤨
Jaaa
Why
U are a learner or advanced
Jaaa
Dunno
Hm well u can also create struck without pointer
.
I have a code. This code delets one line for instance 22 lines later add one line end of line. #include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #include <limits.h> #include <stdbool.h> /* Azad Arkan 20120205303 Bu kod student.txt metin dosyasındaki öğrenci listesini okuyup ve linked list ile listeleyen, bir öğrencinin bilgisini silen (bir satır silme) ve öğrenci listesinin sonuna yeni bir öğrenci bilgisi ekleyen bir c kodudur. */ struct student{ //struct içersindeki deÄŸiÅŸkenler tanımlıyoruz char no[10]; char name[40]; char surname[40]; struct student *next; //adres tanımlıyoruz }studen_t={"no","name","surname",NULL}; int read_student(FILE *f){ //okuma fonksiyonu if(f==NULL) {return -1;} struct student *temp=&studen_t; //studen_t deÄŸiÅŸkeninin adresini tempe atıyoruz char k[150]; while(fgets(k,150,f)!= NULL){ //dosyayı satır satır okuyoruz temp->next=(struct student*) malloc(sizeof(struct student));//next'e hafıza belirliyoruz ve tempi nexte gönderiyoruz char *no=strtok(k,"\t"); char *name=strtok(NULL,"\t"); char *surname=strtok(NULL,"\t"); if(no!=NULL && name!=NULL && surname!=NULL){ strncpy(temp->next->no,no,10); strncpy(temp->next->name,name,40); strncpy(temp->next->surname,surname,40); temp=temp->next;//while bitene kadar temp'i next'in adresini gösterecek ve temp her seferinde artacak. } } temp->next=NULL; //dosyayı sonlandırmak için next'in adresine NULL'a eÅŸitliyoruz. return 0; } void add(){ //ekleme fonksiyonu FILE *f=fopen("student.txt","r"); FILE *a=fopen("student2.txt","a"); struct student *temp=&studen_t; while(temp != NULL){ //verileri student2 dosyasına ekliyoruz temp=temp->next; struct student* temp=(struct student*) malloc(sizeof(struct student)); fprintf(a,"\n"); scanf("%9s",temp->no); fputs(temp->no,a); fprintf(a,"\t"); scanf("%39s",temp->name); fputs(temp->name,a); fprintf(a,"\t"); scanf("%39s",temp->surname); fputs(temp->surname,a); fprintf(a,"\t"); } fclose(a), fclose(f); //dosya kapatma komutu free(temp); } int delet(FILE *f,char no){ //silme fonksiyonu char ch; int del, line=0; del=(int)no; FILE *a=fopen("student.txt","r"); FILE *b=fopen("student2.txt","a"); ch=getc(a); if(ch!=EOF) {line=1;} while(1){ if(del!=line) {putc(ch,b);} //silinmesi istenmeyen satırları yeni dosyaya yazdırma iÅŸlemini yapıyoruz ch=getc(a); if(ch=='\n') {line++;} if(ch==EOF) {break;} } fclose(a),fclose(b); //dosya kapatma iÅŸlemi return 0; } /*int delet(FILE *a,char no); void add(); int read_student(FILE *f); */ int main() { FILE *f=fopen("student.txt","r"); FILE *a=fopen("student2.txt","a"); read_student(a); //okuma fonksiyonunu çağırıyoruz delet(a,22); //silme fonksiyonunu çağırıyoruz add(); //ekleme fonksiyonunu çağırıyoruz rename("student2.txt", "student.txt"); // dosyanın ismini değiştiriyoruz return 0; }
.
My file txt below 13 ABDULLAH G�L 14 ALI AKDEMIR 15 ARIF �Z�ELIK 16 ASIYE DEMIRTAS 17 BERK S�KR� KARAKAYA 18 BERNA YAREN YAGIZ 19 BURAK TIGLI 20 EMRE ERDEM 21 ENES G�LERY�Z 22 ENES KIYMIK 23 FATIH KO� 24 FATIH PACCI 25 FATIH YILMAZ 26 FATMA SELIKA TUG 27 FURKAN �AGLAK 28 HAMZA VEDAT CENGIZ 29 Hasan Ayg�noglu 30 ISMAIL YAL�INKAYA 31 LEYLA S�NMEZ 32 MELEK TUYLU 33 MUHAMMED TALHA SUSAM 34 MURAT TEMIR 35 MURAT ISBIT 36 MURAT CAN DERE 37 MUSTAFA FURKAN GEDIK 38 NUR SEDA SAHKULUBEY 39 OKAN UZUN 40 REMZI �AKIR 41 SAIT FURKAN �AGLAYAN 42 SALISE BEYZANUR
rishin
#include<stdio.h>   void sum(int, int);   void main()   {       int a,b,result;        printf("\nGoing to calculate the sum of two numbers:");       printf("\nEnter two numbers:");       scanf("%d %d",&a,&b);       sum(a,b);   }   void sum(int a, int b)   {       printf("\nThe sum is %d",a+b);       }  
rishin
Please😁
rishin
Function calling is the line sum(a, b)
Thank you... so which parameters should be same to call a function from this program
꧁༒ 9H4WK ☬꧂
Function defination is the line void sum(int a, int b)
rishin
👌
Rahul
👍
Sandro
^\+(?:[0-9]●?){6,14}[0-9]$
Hi Andrew, this pattern doesn't work in ncurses form field, I need to check if the user input a valid phone number. At begin of the string can input or not a + symbol for international code, than at least one digit as phone number, finally the possibility to put wherever between numbers the symbols # and * for special coding. Thank you in advance
IAmMADMAX
I have a problem can anyone help me solving it?
IAmMADMAX
I have tried but i cannot solve it
Igor🇺🇦
I have a problem can anyone help me solving it?
Everyone here has a problem reading minds and even attempt to help without knowing your issue.
Engineer
We intered every youtube learning codding
You mean you only studied when you has to?🙈🤓 Otherwise it was was computer games? When did you start the course? You could have binged watch alot if c++ or cppcon videos on YouTube, but you have to write and study code all by yourself self to keep motivated....
Anonymous
Hi guys how can i add inputted numbers from scanf in a do while loop?
Anonymous
My code only adds 2 inputted numbers ._.
Hadaward 'Solly'
dont use scanf. That's a sin. Try a safer function with a buffer limiting input size, like fgets (could be safer but this will do for now): https://stackoverflow.com/questions/2430303/disadvantages-of-scanf#:~:text=The%20problems%20with%20scanf%20are,pointer%20in%20an%20indeterminate%20location.
Hadaward 'Solly'
if your professor or colleague attempts to force scanf usage, slap and tell them to go back to CS 6.00
olli
dont use scanf. That's a sin. Try a safer function with a buffer limiting input size, like fgets (could be safer but this will do for now): https://stackoverflow.com/questions/2430303/disadvantages-of-scanf#:~:text=The%20problems%20with%20scanf%20are,pointer%20in%20an%20indeterminate%20location.
you can provide an upper bound (buffer size) when using scanf. Instead of suggesting to "slap" people, I'd recommend to read a good C book or the standard. #include <stdio.h> int main() { const char * Data = "0123456789ABCDEF"; char Buffer[8]; sscanf(Data, "%7s", Buffer); printf("%s\n", Buffer); }
Anonymous
I figured it out i had to do it like sum+=num 😁
Anonymous
可以說中文嗎
Anonymous
可以說中文嗎
nope it's English only ig
Anonymous
喔,我還以為是香港人的群
Anonymous
oh
Anonymous
Hey Ihave got a number of questions.....I need the codes
Anonymous
How do you check if an output is an integer
Anonymous
Like it checks it if integer it gives the value else the answer is not an integer
Anonymous
C code
IAmMADMAX
How do you check if an output is an integer
It completely depends on your input
IAmMADMAX
Yes
Sending you in inbox wiat
Anonymous
Ok
Anonymous
It completely depends on your input
Lets say we are writing a code to find squareroot of an input...like 64 its is 8 so it an integer but for a number like 27 the square root is not an integer
IAmMADMAX
Ok i am writing a code
Anonymous
Write a c code that prompts a user to enter numbers and stores them in array ....it then arranges them in ascending order and outputs them.....the user should determine how many numbers to enter
Pavel
this can be misleading tho, when a is a pointer but b is not. So it's not really the type that's modified. int* a, b;
Most coding convention I've seen prohibit declaration/definition of more than one variable in a line. Because it's easier to miss something (this pointer thing, initialization, unused variable, shadowing) when it's all packed in one line.
Anonymous
I'm a beginner btw
olli
Most coding convention I've seen prohibit declaration/definition of more than one variable in a line. Because it's easier to miss something (this pointer thing, initialization, unused variable, shadowing) when it's all packed in one line.
Yes, but this wasn't really the point. There are situations where it might be useful to initialize multiple variables at once, e.g. for(char *Current = Begin, *End = Begin + Len; Current < End; ++Current) { // ...
Pavel
Pavel and Olli check out this
Cast to int (with floor or round) and back to float, then compare original float and this value with epsilon
Pavel
C code
Don't you have round there?
Anonymous
Not there in C
Pavel
have not got any problem for multiply declarations in one line for the whole career
Well, I believe some people didn't get any problems with goto either. Not a good statistic :)
Alex
anyway this is int* p confusing. you should remember int* p1, p2 case
Pavel
Not there in C
You can write it yourself anyway
olli
This is also a good example why having typedefs for pointers can make sense. typedef int* pint: pint a, b; // both pointers
Alex
Well, I believe some people didn't get any problems with goto either. Not a good statistic :)
goto is widely used(check linux kernel source). however its better to avoid, cause hard to read code. You should jump while looking through a code. For several variables in one line no strong arguments. I read lots of book, articles - only today I`ve got this knowledge from you
Alex
This is also a good example why having typedefs for pointers can make sense. typedef int* pint: pint a, b; // both pointers
why not int *a, *b ? you know its pointer and would check for NULL for example. also you know this is first rank
Alex
if I have vars with common logic block, like: int x, y, z; this is more convenient to read than int x; int y; int z;
Najam
Yeah but int x, y, z would do the same and everyone cam read it