Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
Kelompok_Belajar_Alstrudat
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nicolas Manurung
Kelompok_Belajar_Alstrudat
Commits
863e5cd2
Commit
863e5cd2
authored
Mar 14, 2019
by
Nicolas Manurung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete String to Array with Malloc
parent
d1f92ed7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
40 deletions
+0
-40
String to Array with Malloc
String to Array with Malloc
+0
-40
No files found.
String to Array with Malloc
deleted
100644 → 0
View file @
d1f92ed7
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
// Deklarasi Variabel
int n;
int i;
// Masukkan untuk indeks pemesanan memory pada saat malloc nanti
printf("Masukkan Jumlah Mahasiswa: ");
scanf("%d",&n);
// Melakukan Malloc
// variabel nama di pesan sebanyak n. AKan tetapi setiap block memory itu
// memiliki 100 jumlah data bertipe char "(*nama)[100]"
// Begitu juga variabel dari nim, yang mempunyai tipedata sebanyak 20 dan
// memesan memory sebanyak n.
char (*nama)[100] =malloc(sizeof(char[100])*n);
int (*nim) = malloc(sizeof(int[20])*n);
// looping untuk memasukkan data (Dynamic) sebanyak n
for(i = 0; i < n; i++){
printf("Masukkan Nama Mahasiswa ke-%d: ",i+1);
// %[^\n]%*c adalah regex, agar bisa memanipulasi masukan spasi
scanf(" %[^\n]%*c",&nama[i]);
printf("Masukkan Nim Mahasiswa ke-%d: ", i+1);
scanf("%d",&nim[i]);
}
// Looping untuk mengeluarkan output dari pada array
for( i = 0; i < n; i++ ){
printf("Data Mahasiswa ke-%d\n",i+1);
printf("Nama : %s\n",nama[i]);
printf("NIM : %d\n",nim[i]);
printf("\n");
}
return 0;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment