Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
C programming 2nd term
Project
Project
Details
Activity
Releases
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ильин Владимир Александрович
C programming 2nd term
Commits
b85d01c6
Commit
b85d01c6
authored
Apr 27, 2024
by
Ильин Владимир Александрович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Лр 7 задания 1 2 3
parent
3b1cfde2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
147 additions
and
0 deletions
+147
-0
1.c
Лр 7/1.c
+28
-0
2.c
Лр 7/2.c
+40
-0
3.c
Лр 7/3.c
+79
-0
a.out
Лр 7/a.out
+0
-0
No files found.
Лр 7/1.c
0 → 100644
View file @
b85d01c6
#include <curl/curl.h>
#include <curl/easy.h>
#include <stdio.h>
int
main
(
void
)
{
CURL
*
curl
;
CURLcode
res
;
curl
=
curl_easy_init
();
if
(
!
curl
)
{
fprintf
(
stderr
,
"Curl init failed!"
);
return
1
;
}
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
"https://example.com"
);
res
=
curl_easy_perform
(
curl
);
if
(
res
!=
CURLE_OK
)
fprintf
(
stderr
,
"curl failed with %s
\n
"
,
curl_easy_strerror
(
res
));
else
fprintf
(
stdout
,
"curl succeded with code %d
\n
"
,
res
);
curl_easy_cleanup
(
curl
);
return
0
;
}
Лр 7/2.c
0 → 100644
View file @
b85d01c6
#include <curl/curl.h>
#include <curl/easy.h>
#include <stdio.h>
size_t
write_function
(
char
*
buffer
,
size_t
size
,
size_t
nitems
,
void
*
userdata
);
int
main
(
void
)
{
CURL
*
curl
;
CURLcode
res
;
curl
=
curl_easy_init
();
if
(
!
curl
)
{
fprintf
(
stderr
,
"Curl init failed!"
);
return
1
;
}
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
"https://moodle.herzen.spb.ru/pluginfile.php/1671864/mod_resource/content/1/%D0%9B%D0%B0%D0%B1%D0%BE%D1%80%D0%B0%D1%82%D0%BE%D1%80%D0%BD%D0%B0%D1%8F%20%D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0%207%20-%20libcurl.pdf"
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
write_function
);
curl_easy_setopt
(
curl
,
CURLOPT_HEADERDATA
,
stdout
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
NULL
);
res
=
curl_easy_perform
(
curl
);
if
(
res
!=
CURLE_OK
)
fprintf
(
stderr
,
"curl failed with %s
\n
"
,
curl_easy_strerror
(
res
));
else
fprintf
(
stdout
,
"curl succeded with code %d
\n
"
,
res
);
curl_easy_cleanup
(
curl
);
return
0
;
}
size_t
write_function
(
char
*
buffer
,
size_t
size
,
size_t
nitems
,
void
*
stream
)
{
if
(
stream
!=
NULL
)
fwrite
(
buffer
,
size
,
nitems
,
stream
);
return
size
*
nitems
;
}
Лр 7/3.c
0 → 100644
View file @
b85d01c6
#include <curl/curl.h>
#include <curl/easy.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void
usage
();
char
*
get_default_filepath
(
char
*
);
int
main
(
int
argc
,
char
**
argv
)
{
char
*
filepath
=
NULL
;
char
*
url
=
NULL
;
if
(
argc
==
2
){
url
=
argv
[
1
];
filepath
=
get_default_filepath
(
url
);
//filepath is a pointer inside url
}
else
if
(
argc
==
3
){
url
=
argv
[
1
];
filepath
=
argv
[
2
];
}
else
usage
();
printf
(
"url:%s
\n
filepath:%s
\n
"
,
url
,
filepath
);
CURL
*
curl
=
curl_easy_init
();
CURLcode
res
;
if
(
!
curl
)
{
fprintf
(
stderr
,
"Curl init failled, baling!"
);
exit
(
1
);
}
FILE
*
file
;
file
=
fopen
(
filepath
,
"wb"
);
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
url
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
file
);
if
(
!
file
){
fprintf
(
stderr
,
"Could not open file!"
);
exit
(
1
);
}
res
=
curl_easy_perform
(
curl
);
if
(
res
!=
CURLE_OK
)
fprintf
(
stderr
,
"curl_easy_perform() failed: %s
\n
"
,
curl_easy_strerror
(
res
));
else
fprintf
(
stdout
,
"curl returned %s; Downloaded %s
\n
"
,
curl_easy_strerror
(
res
),
filepath
);
fclose
(
file
);
curl_easy_cleanup
(
curl
);
return
0
;
}
char
*
get_default_filepath
(
char
*
url
)
{
char
*
filepath
=
strdup
(
url
);
char
*
tmp
=
strtok
(
filepath
,
"/"
);
while
(
tmp
!=
NULL
)
{
filepath
=
tmp
;
tmp
=
strtok
(
NULL
,
"/"
);
}
return
filepath
;
}
void
usage
(){
puts
(
"usage: <url> <file path>(optional, default is ./<filename on url>)"
);
exit
(
0
);
}
Лр 7/a.out
0 → 100755
View file @
b85d01c6
File added
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