File: example_to_c_char.f90

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (20 lines) | stat: -rw-r--r-- 550 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
program example_to_c_char
  use stdlib_strings, only: to_c_char
  use stdlib_string_type, only: string_type
  use stdlib_kinds, only: c_char
  implicit none
  
  character(kind=c_char), allocatable :: cstr(:),cstr2(:)
  character(*), parameter :: hello = "Hello, World!"
  
  ! Convert character array
  cstr = to_c_char(hello)
  
  ! Convert string type  
  cstr2 = to_c_char(string_type(hello))
    
  if (size(cstr)/=size(cstr2) .or. .not.all(cstr==cstr2)) then 
     error stop 'String conversion error'
  end if
  
end program example_to_c_char